Skip to content

Commit

Permalink
Silently allow --no-update for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardgerardatomicmachinescom committed Feb 10, 2025
1 parent 5dc292b commit 1ddc346
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/poetry/console/commands/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class LockCommand(InstallerCommand):
"Ignore existing lock file"
" and overwrite it with a new lock file created from scratch.",
),
option(
"no-update",
None,
"Do not update locked packages (this is the default behavior).",
),
]

help = """
Expand All @@ -39,6 +44,12 @@ class LockCommand(InstallerCommand):
loggers: ClassVar[list[str]] = ["poetry.repositories.pypi_repository"]

def handle(self) -> int:
if self.option("no-update") and self.option("regenerate"):
self.line_error(
"<error>You cannot set `<fg=yellow;options=bold>--no-update</>` and"
" `<fg=yellow;options=bold>--regenerate</>` at the same time.</error>"
)
return 1
self.installer.lock(update=self.option("regenerate"))

return self.installer.run()
14 changes: 13 additions & 1 deletion tests/console/commands/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ def poetry_with_invalid_lockfile(
return _project_factory("invalid_lock", project_factory, fixture_dir)


@pytest.mark.parametrize("no_update", [True, False])
def test_lock_does_not_update_if_not_necessary(
command_tester_factory: CommandTesterFactory,
poetry_with_old_lockfile: Poetry,
repo: TestRepository,
no_update: bool,
) -> None:
repo.add_package(get_package("sampleproject", "1.3.1"))
repo.add_package(get_package("sampleproject", "2.0.0"))
Expand All @@ -108,7 +110,7 @@ def test_lock_does_not_update_if_not_necessary(
)

tester = command_tester_factory("lock", poetry=poetry_with_old_lockfile)
tester.execute()
tester.execute("--no-update" if no_update else "")

locker = Locker(
lock=poetry_with_old_lockfile.pyproject.file.path.parent / "poetry.lock",
Expand All @@ -124,6 +126,16 @@ def test_lock_does_not_update_if_not_necessary(
assert locked_repository.find_packages(package.to_dependency())


def test_no_update_and_regenerate_at_the_same_time(
command_tester_factory: CommandTesterFactory,
) -> None:
tester = command_tester_factory("lock")
assert tester.execute("--no-update --regenerate") == 1
assert tester.io.fetch_error() == (
"You cannot set `--no-update` and `--regenerate` at the same time.\n"
)


@pytest.mark.parametrize("regenerate", [True, False])
def test_lock_always_updates_path_dependencies(
command_tester_factory: CommandTesterFactory,
Expand Down

0 comments on commit 1ddc346

Please sign in to comment.