Skip to content

Commit

Permalink
Add --sync CLI option to update subcommand (#8931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cypher1 committed Feb 6, 2024
1 parent 300e2ee commit f3bb139
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
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

0 comments on commit f3bb139

Please sign in to comment.