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

Add --sync CLI option to update subcommand #8931

Merged
merged 8 commits into from
Feb 6, 2024
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
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ You can do this using the `add` command.
* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose).
* `--no-dev` : Do not update the development dependencies. (**Deprecated**, use `--only main` or `--without dev` instead)
* `--lock` : Do not perform install (only update the lockfile).
* `--sync`: Synchronize the environment with the locked packages and the specified groups.

{{% note %}}
When `--only` is specified, `--with` and `--without` options are ignored.
Expand Down
7 changes: 7 additions & 0 deletions src/poetry/console/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class UpdateCommand(InstallerCommand):
"Do not update the development dependencies."
" (<warning>Deprecated</warning>)",
),
option(
"sync",
None,
"Synchronize the environment with the locked packages and the specified"
" groups.",
),
option(
"dry-run",
None,
Expand All @@ -41,6 +47,7 @@ def handle(self) -> int:

self.installer.only_groups(self.activated_groups)
self.installer.dry_run(self.option("dry-run"))
self.installer.requires_synchronization(self.option("sync"))
self.installer.execute_operations(not self.option("lock"))

# Force update
Expand Down
20 changes: 20 additions & 0 deletions tests/console/commands/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

import pytest

from poetry.console.commands.update import UpdateCommand
from tests.helpers import get_package


if TYPE_CHECKING:
from pytest_mock import MockerFixture

from poetry.poetry import Poetry
from tests.helpers import TestRepository
from tests.types import CommandTesterFactory
Expand Down Expand Up @@ -80,3 +83,20 @@ def test_update_prints_operations(

assert ("Package operations:" in output) is expected
assert ("Installing docker (4.3.1)" in output) is expected


def test_update_sync_option_is_passed_to_the_installer(
poetry_with_outdated_lockfile: Poetry,
command_tester_factory: CommandTesterFactory,
mocker: MockerFixture,
) -> None:
"""
The --sync option is passed properly to the installer from update.
"""
tester = command_tester_factory("update", poetry=poetry_with_outdated_lockfile)
assert isinstance(tester.command, UpdateCommand)
mocker.patch.object(tester.command.installer, "run", return_value=1)

tester.execute("--sync")

assert tester.command.installer._requires_synchronization
Loading