Commit ebf6b483 by Riccardo Albertazzi Committed by GitHub

fix: do not print unwanted operations on --lock (#7915)

Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
parent 3bed8d67
...@@ -108,6 +108,10 @@ class Executor: ...@@ -108,6 +108,10 @@ class Executor:
def removals_count(self) -> int: def removals_count(self) -> int:
return self._executed["uninstall"] return self._executed["uninstall"]
@property
def enabled(self) -> bool:
return self._enabled
def supports_fancy_output(self) -> bool: def supports_fancy_output(self) -> bool:
return self._io.output.is_decorated() and not self._dry_run return self._io.output.is_decorated() and not self._dry_run
......
...@@ -53,7 +53,6 @@ class Installer: ...@@ -53,7 +53,6 @@ class Installer:
self._requires_synchronization = False self._requires_synchronization = False
self._update = False self._update = False
self._verbose = False self._verbose = False
self._write_lock = True
self._groups: Iterable[str] | None = None self._groups: Iterable[str] | None = None
self._skip_directory = False self._skip_directory = False
self._lock = False self._lock = False
...@@ -99,7 +98,6 @@ class Installer: ...@@ -99,7 +98,6 @@ class Installer:
if self.is_dry_run(): if self.is_dry_run():
self.verbose(True) self.verbose(True)
self._write_lock = False
return self._do_install() return self._do_install()
...@@ -269,7 +267,7 @@ class Installer: ...@@ -269,7 +267,7 @@ class Installer:
lockfile_repo = LockfileRepository() lockfile_repo = LockfileRepository()
self._populate_lockfile_repo(lockfile_repo, ops) self._populate_lockfile_repo(lockfile_repo, ops)
if self._lock and self._update: if not self.executor.enabled:
# If we are only in lock mode, no need to go any further # If we are only in lock mode, no need to go any further
self._write_lock_file(lockfile_repo) self._write_lock_file(lockfile_repo)
return 0 return 0
...@@ -348,7 +346,7 @@ class Installer: ...@@ -348,7 +346,7 @@ class Installer:
return status return status
def _write_lock_file(self, repo: LockfileRepository, force: bool = False) -> None: def _write_lock_file(self, repo: LockfileRepository, force: bool = False) -> None:
if self._write_lock and (force or self._update): if not self.is_dry_run() and (force or self._update):
updated_lock = self._locker.set_lock_data(self._package, repo.packages) updated_lock = self._locker.set_lock_data(self._package, repo.packages)
if updated_lock: if updated_lock:
......
...@@ -16,7 +16,7 @@ if TYPE_CHECKING: ...@@ -16,7 +16,7 @@ if TYPE_CHECKING:
@pytest.fixture @pytest.fixture
def poetry_with_up_to_date_lockfile( def poetry_with_outdated_lockfile(
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
) -> Poetry: ) -> Poetry:
source = fixture_dir("outdated_lock") source = fixture_dir("outdated_lock")
...@@ -37,21 +37,46 @@ def poetry_with_up_to_date_lockfile( ...@@ -37,21 +37,46 @@ def poetry_with_up_to_date_lockfile(
) )
def test_update_with_dry_run_keep_files_intact( def test_update_with_dry_run_keep_files_intact(
command: str, command: str,
poetry_with_up_to_date_lockfile: Poetry, poetry_with_outdated_lockfile: Poetry,
repo: TestRepository, repo: TestRepository,
command_tester_factory: CommandTesterFactory, command_tester_factory: CommandTesterFactory,
) -> None: ) -> None:
tester = command_tester_factory("update", poetry=poetry_with_up_to_date_lockfile) tester = command_tester_factory("update", poetry=poetry_with_outdated_lockfile)
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read() original_pyproject_content = poetry_with_outdated_lockfile.file.read()
original_lockfile_content = poetry_with_up_to_date_lockfile._locker.lock_data original_lockfile_content = poetry_with_outdated_lockfile._locker.lock_data
repo.add_package(get_package("docker", "4.3.0")) repo.add_package(get_package("docker", "4.3.0"))
repo.add_package(get_package("docker", "4.3.1")) repo.add_package(get_package("docker", "4.3.1"))
tester.execute(command) tester.execute(command)
assert poetry_with_up_to_date_lockfile.file.read() == original_pyproject_content assert poetry_with_outdated_lockfile.file.read() == original_pyproject_content
assert ( assert poetry_with_outdated_lockfile._locker.lock_data == original_lockfile_content
poetry_with_up_to_date_lockfile._locker.lock_data == original_lockfile_content
)
@pytest.mark.parametrize(
("command", "expected"),
[
("", True),
("--dry-run", True),
("--lock", False),
],
)
def test_update_prints_operations(
command: str,
expected: bool,
poetry_with_outdated_lockfile: Poetry,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
) -> None:
tester = command_tester_factory("update", poetry=poetry_with_outdated_lockfile)
repo.add_package(get_package("docker", "4.3.0"))
repo.add_package(get_package("docker", "4.3.1"))
tester.execute(command)
output = tester.io.fetch_output()
assert ("Package operations:" in output) is expected
assert ("Installing docker (4.3.1)" in output) is expected
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment