Skip to content

Commit ebf6b48

Browse files
fix: do not print unwanted operations on --lock (#7915)
Co-authored-by: Randy Döring <[email protected]>
1 parent 3bed8d6 commit ebf6b48

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

src/poetry/installation/executor.py

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def updates_count(self) -> int:
108108
def removals_count(self) -> int:
109109
return self._executed["uninstall"]
110110

111+
@property
112+
def enabled(self) -> bool:
113+
return self._enabled
114+
111115
def supports_fancy_output(self) -> bool:
112116
return self._io.output.is_decorated() and not self._dry_run
113117

src/poetry/installation/installer.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def __init__(
5353
self._requires_synchronization = False
5454
self._update = False
5555
self._verbose = False
56-
self._write_lock = True
5756
self._groups: Iterable[str] | None = None
5857
self._skip_directory = False
5958
self._lock = False
@@ -99,7 +98,6 @@ def run(self) -> int:
9998

10099
if self.is_dry_run():
101100
self.verbose(True)
102-
self._write_lock = False
103101

104102
return self._do_install()
105103

@@ -269,7 +267,7 @@ def _do_install(self) -> int:
269267
lockfile_repo = LockfileRepository()
270268
self._populate_lockfile_repo(lockfile_repo, ops)
271269

272-
if self._lock and self._update:
270+
if not self.executor.enabled:
273271
# If we are only in lock mode, no need to go any further
274272
self._write_lock_file(lockfile_repo)
275273
return 0
@@ -348,7 +346,7 @@ def _do_install(self) -> int:
348346
return status
349347

350348
def _write_lock_file(self, repo: LockfileRepository, force: bool = False) -> None:
351-
if self._write_lock and (force or self._update):
349+
if not self.is_dry_run() and (force or self._update):
352350
updated_lock = self._locker.set_lock_data(self._package, repo.packages)
353351

354352
if updated_lock:

tests/console/commands/test_update.py

+34-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
@pytest.fixture
19-
def poetry_with_up_to_date_lockfile(
19+
def poetry_with_outdated_lockfile(
2020
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
2121
) -> Poetry:
2222
source = fixture_dir("outdated_lock")
@@ -37,21 +37,46 @@ def poetry_with_up_to_date_lockfile(
3737
)
3838
def test_update_with_dry_run_keep_files_intact(
3939
command: str,
40-
poetry_with_up_to_date_lockfile: Poetry,
40+
poetry_with_outdated_lockfile: Poetry,
4141
repo: TestRepository,
4242
command_tester_factory: CommandTesterFactory,
4343
) -> None:
44-
tester = command_tester_factory("update", poetry=poetry_with_up_to_date_lockfile)
44+
tester = command_tester_factory("update", poetry=poetry_with_outdated_lockfile)
4545

46-
original_pyproject_content = poetry_with_up_to_date_lockfile.file.read()
47-
original_lockfile_content = poetry_with_up_to_date_lockfile._locker.lock_data
46+
original_pyproject_content = poetry_with_outdated_lockfile.file.read()
47+
original_lockfile_content = poetry_with_outdated_lockfile._locker.lock_data
4848

4949
repo.add_package(get_package("docker", "4.3.0"))
5050
repo.add_package(get_package("docker", "4.3.1"))
5151

5252
tester.execute(command)
5353

54-
assert poetry_with_up_to_date_lockfile.file.read() == original_pyproject_content
55-
assert (
56-
poetry_with_up_to_date_lockfile._locker.lock_data == original_lockfile_content
57-
)
54+
assert poetry_with_outdated_lockfile.file.read() == original_pyproject_content
55+
assert poetry_with_outdated_lockfile._locker.lock_data == original_lockfile_content
56+
57+
58+
@pytest.mark.parametrize(
59+
("command", "expected"),
60+
[
61+
("", True),
62+
("--dry-run", True),
63+
("--lock", False),
64+
],
65+
)
66+
def test_update_prints_operations(
67+
command: str,
68+
expected: bool,
69+
poetry_with_outdated_lockfile: Poetry,
70+
repo: TestRepository,
71+
command_tester_factory: CommandTesterFactory,
72+
) -> None:
73+
tester = command_tester_factory("update", poetry=poetry_with_outdated_lockfile)
74+
75+
repo.add_package(get_package("docker", "4.3.0"))
76+
repo.add_package(get_package("docker", "4.3.1"))
77+
78+
tester.execute(command)
79+
output = tester.io.fetch_output()
80+
81+
assert ("Package operations:" in output) is expected
82+
assert ("Installing docker (4.3.1)" in output) is expected

0 commit comments

Comments
 (0)