Skip to content

Commit

Permalink
respect --no-cache at poetry install
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and neersighted committed Sep 11, 2022
1 parent 60168d6 commit 6ae844b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def create_poetry(
base_poetry.package,
locker,
config,
disable_cache,
)

# Configuring sources
Expand Down
5 changes: 4 additions & 1 deletion src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,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)

Expand Down
5 changes: 4 additions & 1 deletion src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
package: ProjectPackage,
locker: Locker,
config: Config,
disable_cache: bool = False,
) -> None:
from poetry.repositories.pool import Pool

Expand All @@ -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:
Expand All @@ -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

Expand Down
24 changes: 24 additions & 0 deletions tests/console/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"]

0 comments on commit 6ae844b

Please sign in to comment.