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

Silently allow --no-update for backward compatibility #10164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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