Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def updates_count(self) -> int:
def removals_count(self) -> int:
return self._executed["uninstall"]

@property
def enabled(self) -> bool:
return self._enabled

def supports_fancy_output(self) -> bool:
return self._io.output.is_decorated() and not self._dry_run

Expand Down
6 changes: 2 additions & 4 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(
self._requires_synchronization = False
self._update = False
self._verbose = False
self._write_lock = True
radoering marked this conversation as resolved.
Show resolved Hide resolved
self._groups: Iterable[str] | None = None
self._skip_directory = False
self._lock = False
Expand Down Expand Up @@ -99,7 +98,6 @@ def run(self) -> int:

if self.is_dry_run():
self.verbose(True)
self._write_lock = False

return self._do_install()

Expand Down Expand Up @@ -269,7 +267,7 @@ def _do_install(self) -> int:
lockfile_repo = LockfileRepository()
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
self._write_lock_file(lockfile_repo)
return 0
Expand Down Expand Up @@ -348,7 +346,7 @@ def _do_install(self) -> int:
return status

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)

if updated_lock:
Expand Down
43 changes: 34 additions & 9 deletions tests/console/commands/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@pytest.fixture
def poetry_with_up_to_date_lockfile(
def poetry_with_outdated_lockfile(
project_factory: ProjectFactory, fixture_dir: FixtureDirGetter
) -> Poetry:
source = fixture_dir("outdated_lock")
Expand All @@ -37,21 +37,46 @@ def poetry_with_up_to_date_lockfile(
)
def test_update_with_dry_run_keep_files_intact(
command: str,
poetry_with_up_to_date_lockfile: Poetry,
poetry_with_outdated_lockfile: Poetry,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
) -> 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_lockfile_content = poetry_with_up_to_date_lockfile._locker.lock_data
original_pyproject_content = poetry_with_outdated_lockfile.file.read()
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.1"))

tester.execute(command)

assert poetry_with_up_to_date_lockfile.file.read() == original_pyproject_content
assert (
poetry_with_up_to_date_lockfile._locker.lock_data == original_lockfile_content
)
assert poetry_with_outdated_lockfile.file.read() == original_pyproject_content
assert poetry_with_outdated_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