From 9191fef9c31bcf88996185b0b9c4abb3c52940e6 Mon Sep 17 00:00:00 2001 From: Jay Pratt Date: Thu, 1 Feb 2024 16:05:03 +1100 Subject: [PATCH 1/8] Add --sync CLI option to update subcommand --- src/poetry/console/commands/update.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/poetry/console/commands/update.py b/src/poetry/console/commands/update.py index 57b173000a9..59c17caaa9b 100644 --- a/src/poetry/console/commands/update.py +++ b/src/poetry/console/commands/update.py @@ -23,6 +23,12 @@ class UpdateCommand(InstallerCommand): "Do not update the development dependencies." " (Deprecated)", ), + option( + "sync", + None, + "Synchronize the environment with the locked packages and the specified" + " groups.", + ), option( "dry-run", None, @@ -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 From d3baf93bfa9fb2a2b8736145c58899b006f52aba Mon Sep 17 00:00:00 2001 From: J Pratt Date: Mon, 5 Feb 2024 17:58:42 +1100 Subject: [PATCH 2/8] Add test for update --sync --- tests/console/commands/test_update.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/console/commands/test_update.py b/tests/console/commands/test_update.py index b8b2e06684b..711c52f8ba5 100644 --- a/tests/console/commands/test_update.py +++ b/tests/console/commands/test_update.py @@ -9,6 +9,7 @@ if TYPE_CHECKING: from poetry.poetry import Poetry + from pytest_mock import MockerFixture from tests.helpers import TestRepository from tests.types import CommandTesterFactory from tests.types import FixtureDirGetter @@ -80,3 +81,17 @@ def test_update_prints_operations( assert ("Package operations:" in output) is expected assert ("Installing docker (4.3.1)" in output) is expected + +@pytest.fixture() +def test_update_sync_option_is_passed_to_the_installer( + mocker: MockerFixture +) -> None: + """ + The --sync option is passed properly to the installer from update. + """ + tester = command_tester_factory("update", poetry=poetry_with_outdated_lockfile) + mocker.patch.object(tester.command.installer, "run", return_value=1) + + tester.execute("--sync") + + assert tester.command.installer._requires_synchronization From 10188829bba7c0db5b44046fcfa9ef1c90911385 Mon Sep 17 00:00:00 2001 From: J Pratt Date: Mon, 5 Feb 2024 18:04:37 +1100 Subject: [PATCH 3/8] Update docs for update subcommand --sync option --- docs/cli.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/cli.md b/docs/cli.md index e3110d9821a..f77d2f851e7 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -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. From b8113560ada15b9a7fa0ffe65090fc4c5f3dca06 Mon Sep 17 00:00:00 2001 From: J Pratt Date: Mon, 5 Feb 2024 18:09:25 +1100 Subject: [PATCH 4/8] Fix for missing fixture in update sync test --- tests/console/commands/test_update.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/console/commands/test_update.py b/tests/console/commands/test_update.py index 711c52f8ba5..0d55e36e075 100644 --- a/tests/console/commands/test_update.py +++ b/tests/console/commands/test_update.py @@ -84,6 +84,7 @@ def test_update_prints_operations( @pytest.fixture() def test_update_sync_option_is_passed_to_the_installer( + command_tester_factory: CommandTesterFactory, mocker: MockerFixture ) -> None: """ From 41a29223e03bc63d5f3dddd2b1aa1b00b19d4b1c Mon Sep 17 00:00:00 2001 From: J Pratt Date: Mon, 5 Feb 2024 18:12:12 +1100 Subject: [PATCH 5/8] Auto format --- tests/console/commands/test_update.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/console/commands/test_update.py b/tests/console/commands/test_update.py index 0d55e36e075..04d851b1061 100644 --- a/tests/console/commands/test_update.py +++ b/tests/console/commands/test_update.py @@ -82,10 +82,10 @@ def test_update_prints_operations( assert ("Package operations:" in output) is expected assert ("Installing docker (4.3.1)" in output) is expected + @pytest.fixture() def test_update_sync_option_is_passed_to_the_installer( - command_tester_factory: CommandTesterFactory, - mocker: MockerFixture + command_tester_factory: CommandTesterFactory, mocker: MockerFixture ) -> None: """ The --sync option is passed properly to the installer from update. From afce28dc022e851daea4de6e1156cf3c2afd2813 Mon Sep 17 00:00:00 2001 From: J Pratt Date: Mon, 5 Feb 2024 18:16:28 +1100 Subject: [PATCH 6/8] Add poetry fixture --- tests/console/commands/test_update.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/console/commands/test_update.py b/tests/console/commands/test_update.py index 04d851b1061..188af0bbdba 100644 --- a/tests/console/commands/test_update.py +++ b/tests/console/commands/test_update.py @@ -83,9 +83,10 @@ def test_update_prints_operations( assert ("Installing docker (4.3.1)" in output) is expected -@pytest.fixture() def test_update_sync_option_is_passed_to_the_installer( - command_tester_factory: CommandTesterFactory, mocker: MockerFixture + poetry_with_outdated_lockfile: Poetry, + command_tester_factory: CommandTesterFactory, + mocker: MockerFixture, ) -> None: """ The --sync option is passed properly to the installer from update. From e1a93421bb04a87536459f4dd9c3b70f9123c197 Mon Sep 17 00:00:00 2001 From: J Pratt Date: Mon, 5 Feb 2024 18:29:20 +1100 Subject: [PATCH 7/8] Add assertion that the command under test is the expected UpdateCommand type --- tests/console/commands/test_update.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/console/commands/test_update.py b/tests/console/commands/test_update.py index 188af0bbdba..42da10ba945 100644 --- a/tests/console/commands/test_update.py +++ b/tests/console/commands/test_update.py @@ -5,6 +5,7 @@ import pytest from tests.helpers import get_package +from poetry.console.commands.update import UpdateCommand if TYPE_CHECKING: @@ -92,6 +93,7 @@ def test_update_sync_option_is_passed_to_the_installer( 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") From 80c282ed7246614f46836215ca7bb5cd5ab2fad3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:51:23 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/console/commands/test_update.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/console/commands/test_update.py b/tests/console/commands/test_update.py index 42da10ba945..6b48071d612 100644 --- a/tests/console/commands/test_update.py +++ b/tests/console/commands/test_update.py @@ -4,13 +4,14 @@ import pytest -from tests.helpers import get_package from poetry.console.commands.update import UpdateCommand +from tests.helpers import get_package if TYPE_CHECKING: - from poetry.poetry import Poetry from pytest_mock import MockerFixture + + from poetry.poetry import Poetry from tests.helpers import TestRepository from tests.types import CommandTesterFactory from tests.types import FixtureDirGetter