From 46f3ede9fcb8660ada1193e93660d386570b207c Mon Sep 17 00:00:00 2001 From: Elliot <3186037+elliot-100@users.noreply.github.com> Date: Mon, 14 Oct 2024 22:47:09 +0100 Subject: [PATCH 1/2] feat: in `show {package}` output, clarify meaning of 'required by' entries (#9750) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/cli.md | 2 +- src/poetry/console/commands/show.py | 2 +- tests/console/commands/test_show.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index f8cd49cc1fc..42bfb181fc4 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -509,7 +509,7 @@ dependencies - pytzdata >=2017.2.2 required by - - calendar >=1.4.0 + - calendar requires >=1.4.0 ``` ### Options diff --git a/src/poetry/console/commands/show.py b/src/poetry/console/commands/show.py index 8e13cb87adc..b47b4574666 100644 --- a/src/poetry/console/commands/show.py +++ b/src/poetry/console/commands/show.py @@ -195,7 +195,7 @@ def _display_single_package_information( self.line("") self.line("required by") for parent, requires_version in required_by.items(): - self.line(f" - {parent} {requires_version}") + self.line(f" - {parent} requires {requires_version}") return 0 diff --git a/tests/console/commands/test_show.py b/tests/console/commands/test_show.py index cc62cacdcca..22594af6e87 100644 --- a/tests/console/commands/test_show.py +++ b/tests/console/commands/test_show.py @@ -1975,7 +1975,7 @@ def test_show_required_by_deps( - msgpack-python >=0.5 <0.6 required by - - pendulum >=0.2.0 <0.3.0 + - pendulum requires >=0.2.0 <0.3.0 """.splitlines() actual = [line.rstrip() for line in tester.io.fetch_output().splitlines()] assert actual == expected From dcd5ae1f67abb9ed49a0e7b89235b6f3c4e30661 Mon Sep 17 00:00:00 2001 From: Philipp Schneeberger <43273616+schneebuzz@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:22:05 +0200 Subject: [PATCH 2/2] feat(install): add `--all-groups` flag to install all dependency groups (#9744) --- docs/cli.md | 25 +++++++++------ src/poetry/console/commands/group_command.py | 6 ++++ src/poetry/console/commands/install.py | 20 ++++++++++-- tests/console/commands/test_install.py | 32 ++++++++++++++++++-- 4 files changed, 69 insertions(+), 14 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 42bfb181fc4..fb94f416ce1 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -164,6 +164,12 @@ You can also select optional dependency groups with the `--with` option. poetry install --with test,docs ``` +To install all dependency groups including the optional groups, use the ``--all-groups`` flag. + +```bash +poetry install --all-groups +``` + It's also possible to only install specific dependency groups by using the `only` option. ```bash @@ -254,9 +260,10 @@ poetry install --compile * `--sync`: Synchronize the environment with the locked packages and the specified groups. * `--no-root`: Do not install the root package (your project). * `--no-directory`: Skip all directory path dependencies (including transitive ones). -* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose). +* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`). * `--extras (-E)`: Features to install (multiple values allowed). -* `--all-extras`: Install all extra features (conflicts with --extras). +* `--all-extras`: Install all extra features (conflicts with `--extras`). +* `--all-groups`: Install dependencies from all groups (conflicts with `--only`, `--with`, and `--without`). * `--compile`: Compile Python source files to bytecode. * `--remove-untracked`: Remove dependencies not presented in the lock file. (**Deprecated**, use `--sync` instead) @@ -295,7 +302,7 @@ You can do this using the `add` command. * `--without`: The dependency groups to ignore. * `--with`: The optional dependency groups to include. * `--only`: The only dependency groups to include. -* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose). +* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables `--verbose`). * `--lock` : Do not perform install (only update the lockfile). * `--sync`: Synchronize the environment with the locked packages and the specified groups. @@ -456,7 +463,7 @@ about dependency groups. * `--platform`: Platforms for which the dependency must be installed. * `--source`: Name of the source to use to install the package. * `--allow-prereleases`: Accept prereleases. -* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose). +* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`). * `--lock`: Do not perform install (only update the lockfile). @@ -482,7 +489,7 @@ about dependency groups. * `--group (-G)`: The group to remove the dependency from. * `--dev (-D)`: Removes a package from the development dependencies. (shortcut for `-G dev`) -* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose). +* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables `--verbose`). * `--lock`: Do not perform operations (only update the lockfile). @@ -991,7 +998,7 @@ poetry self add artifacts-keyring * `--extras (-E)`: Extras to activate for the dependency. (multiple values allowed) * `--allow-prereleases`: Accept prereleases. * `--source`: Name of the source to use to install the package. -* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose). +* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`). ### self update @@ -1009,7 +1016,7 @@ poetry self update #### Options * `--preview`: Allow the installation of pre-release versions. -* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose). +* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`). ### self lock @@ -1063,7 +1070,7 @@ poetry self remove poetry-plugin-export #### Options -* `--dry-run`: Outputs the operations but will not execute anything (implicitly enables --verbose). +* `--dry-run`: Outputs the operations but will not execute anything (implicitly enables `--verbose`). ### self install @@ -1082,4 +1089,4 @@ poetry self install --sync #### Options * `--sync`: Synchronize the environment with the locked packages and the specified groups. -* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose). +* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`). diff --git a/src/poetry/console/commands/group_command.py b/src/poetry/console/commands/group_command.py index f2ec9fbe52c..06dea92cc78 100644 --- a/src/poetry/console/commands/group_command.py +++ b/src/poetry/console/commands/group_command.py @@ -79,6 +79,12 @@ def activated_groups(self) -> set[str]: for groups in self.option(key, "") for group in groups.split(",") } + + if self.option("all-groups"): + groups["with"] = self.poetry.package.dependency_group_names( + include_optional=True + ) + self._validate_group_options(groups) if groups["only"] and (groups["with"] or groups["without"]): diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py index 4c7c7d24153..972d04d8f77 100644 --- a/src/poetry/console/commands/install.py +++ b/src/poetry/console/commands/install.py @@ -50,6 +50,7 @@ class InstallCommand(InstallerCommand): multiple=True, ), option("all-extras", None, "Install all extra dependencies."), + option("all-groups", None, "Install dependencies from all groups."), option("only-root", None, "Exclude all dependencies."), option( "compile", @@ -104,12 +105,14 @@ def handle(self) -> int: return 1 if self.option("only-root") and any( - self.option(key) for key in {"with", "without", "only"} + self.option(key) for key in {"with", "without", "only", "all-groups"} ): self.line_error( "The `--with`," - " `--without` and" - " `--only` options cannot be used with" + " `--without`," + " `--only` and" + " `--all-groups`" + " options cannot be used with" " the `--only-root`" " option." ) @@ -122,6 +125,17 @@ def handle(self) -> int: ) return 1 + if ( + self.option("only") or self.option("with") or self.option("without") + ) and self.option("all-groups"): + self.line_error( + "You cannot specify `--with`," + " `--without`, or" + " `--only` when using" + " `--all-groups`." + ) + return 1 + extras: list[str] if self.option("all-extras"): extras = list(self.poetry.package.extras.keys()) diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index 85162a31e5e..ae163df3ec2 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -104,6 +104,7 @@ def _project_factory( ("--without foo,bar", {MAIN_GROUP, "baz", "bim"}), (f"--without {MAIN_GROUP}", {"foo", "bar", "baz", "bim"}), ("--with foo,bar --without baz --without bim --only bam", {"bam"}), + ("--all-groups", {MAIN_GROUP, "foo", "bar", "baz", "bim", "bam"}), # net result zero options ("--with foo", {MAIN_GROUP, "foo", "bar", "baz", "bim"}), ("--without bam", {MAIN_GROUP, "foo", "bar", "baz", "bim"}), @@ -285,9 +286,10 @@ def test_extras_conflicts_all_extras( "--without foo", "--with foo,bar --without baz", "--only foo", + "--all-groups", ], ) -def test_only_root_conflicts_with_without_only( +def test_only_root_conflicts_with_without_only_all_groups( options: str, tester: CommandTester, mocker: MockerFixture, @@ -300,11 +302,37 @@ def test_only_root_conflicts_with_without_only( assert tester.status_code == 1 assert ( tester.io.fetch_error() - == "The `--with`, `--without` and `--only` options cannot be used with" + == "The `--with`, `--without`, `--only` and `--all-groups` options cannot be used with" " the `--only-root` option.\n" ) +@pytest.mark.parametrize( + "options", + [ + "--with foo", + "--without foo", + "--with foo,bar --without baz", + "--only foo", + ], +) +def test_all_groups_conflicts_with_only_with_without( + options: str, + tester: CommandTester, + mocker: MockerFixture, +) -> None: + assert isinstance(tester.command, InstallerCommand) + mocker.patch.object(tester.command.installer, "run", return_value=0) + + tester.execute(f"{options} --all-groups") + + assert tester.status_code == 1 + assert ( + tester.io.fetch_error() + == "You cannot specify `--with`, `--without`, or `--only` when using `--all-groups`.\n" + ) + + @pytest.mark.parametrize( ("options", "valid_groups", "should_raise"), [