From 49295b5a423a7009e176fdcfc7db68528c3e4d9c Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 11 Sep 2022 16:05:29 +0100 Subject: [PATCH] respect --no-cache at poetry install (cherry picked from commit 6ae844bc67701e6c5fbb0ebe566dfef13ed69069) --- src/poetry/console/application.py | 1 + src/poetry/factory.py | 1 + src/poetry/installation/executor.py | 5 ++++- src/poetry/installation/installer.py | 5 ++++- src/poetry/poetry.py | 6 ++++++ tests/console/test_application.py | 24 ++++++++++++++++++++++++ 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/poetry/console/application.py b/src/poetry/console/application.py index 2b6bd633c50..e54c679be9c 100644 --- a/src/poetry/console/application.py +++ b/src/poetry/console/application.py @@ -327,6 +327,7 @@ def configure_installer_for_command(command: InstallerCommand, io: IO) -> None: poetry.locker, poetry.pool, poetry.config, + disable_cache=poetry.disable_cache, ) installer.use_executor(poetry.config.get("experimental.new-installer", False)) command.set_installer(installer) diff --git a/src/poetry/factory.py b/src/poetry/factory.py index dfa0a4d63aa..5910def0735 100644 --- a/src/poetry/factory.py +++ b/src/poetry/factory.py @@ -92,6 +92,7 @@ def create_poetry( base_poetry.package, locker, config, + disable_cache, ) # Configuring sources diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index 14f31c55292..8a5f996d09a 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -52,13 +52,16 @@ def __init__( config: Config, io: IO, parallel: bool | None = None, + disable_cache: bool = False, ) -> None: self._env = env self._io = io self._dry_run = False self._enabled = True self._verbose = False - self._authenticator = Authenticator(config, self._io) + self._authenticator = Authenticator( + config, self._io, disable_cache=disable_cache + ) self._chef = Chef(config, self._env) self._chooser = Chooser(pool, self._env, config) diff --git a/src/poetry/installation/installer.py b/src/poetry/installation/installer.py index b590483bbc5..38127feb423 100644 --- a/src/poetry/installation/installer.py +++ b/src/poetry/installation/installer.py @@ -43,6 +43,7 @@ def __init__( config: Config, installed: Repository | None = None, executor: Executor | None = None, + disable_cache: bool = False, ) -> None: self._io = io self._env = env @@ -65,7 +66,9 @@ def __init__( self._extras: list[str] = [] if executor is None: - executor = Executor(self._env, self._pool, config, self._io) + executor = Executor( + self._env, self._pool, config, self._io, disable_cache=disable_cache + ) self._executor = executor self._use_executor = False diff --git a/src/poetry/poetry.py b/src/poetry/poetry.py index 4459bdd43a1..42ceff2e47e 100644 --- a/src/poetry/poetry.py +++ b/src/poetry/poetry.py @@ -30,6 +30,7 @@ def __init__( package: ProjectPackage, locker: Locker, config: Config, + disable_cache: bool = False, ) -> None: from poetry.repositories.pool import Pool @@ -39,6 +40,7 @@ def __init__( self._config = config self._pool = Pool() self._plugin_manager: PluginManager | None = None + self._disable_cache = disable_cache @property def locker(self) -> Locker: @@ -52,6 +54,10 @@ def pool(self) -> Pool: def config(self) -> Config: return self._config + @property + def disable_cache(self) -> bool: + return self._disable_cache + def set_locker(self, locker: Locker) -> Poetry: self._locker = locker diff --git a/tests/console/test_application.py b/tests/console/test_application.py index 06a99421ca5..9ed2e2aeb54 100644 --- a/tests/console/test_application.py +++ b/tests/console/test_application.py @@ -11,6 +11,7 @@ from poetry.console.application import Application from poetry.console.commands.command import Command from poetry.plugins.application_plugin import ApplicationPlugin +from poetry.utils.authenticator import Authenticator from tests.helpers import mock_metadata_entry_points @@ -99,3 +100,26 @@ def test_application_verify_source_cache_flag(disable_cache: bool): for repo in app.poetry.pool.repositories: assert repo._disable_cache == disable_cache + + +@pytest.mark.parametrize("disable_cache", [True, False]) +def test_application_verify_cache_flag_at_install( + mocker: MockerFixture, disable_cache: bool +) -> None: + app = Application() + + tester = ApplicationTester(app) + command = "install --dry-run" + + if disable_cache: + command = f"{command} --no-cache" + + spy = mocker.spy(Authenticator, "__init__") + + tester.execute(command) + + assert spy.call_count == 2 + for call in spy.mock_calls: + (name, args, kwargs) = call + assert "disable_cache" in kwargs + assert disable_cache is kwargs["disable_cache"]