From 188721822a96accaa30ff57c12222af751b2c5b5 Mon Sep 17 00:00:00 2001 From: Kyle Roeschley Date: Thu, 14 Apr 2022 14:36:58 -0500 Subject: [PATCH 1/7] Add --all-extras flag for poetry install --- src/poetry/console/commands/install.py | 21 ++++++++++---- tests/console/commands/test_install.py | 40 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py index b0fad0d8d3e..a724a83401d 100644 --- a/src/poetry/console/commands/install.py +++ b/src/poetry/console/commands/install.py @@ -52,6 +52,7 @@ class InstallCommand(InstallerCommand): flag=False, multiple=True, ), + option("all-extras", None, "Install all extra dependencies."), ] help = """The install command reads the poetry.lock file from @@ -79,12 +80,20 @@ def handle(self) -> int: self.poetry.config.get("experimental.new-installer", False) ) - extras = [] - for extra in self.option("extras"): - if " " in extra: - extras += [e.strip() for e in extra.split(" ")] - else: - extras.append(extra) + if self.option("extras") and self.option("all-extras"): + raise ValueError( + "You cannot specify explicit extras while installing all extras" + ) + + if self.option("all-extras"): + extras = list(self.poetry.package.extras.keys()) + else: + extras = [] + for extra in self.option("extras"): + if " " in extra: + extras += [e.strip() for e in extra.split(" ")] + else: + extras.append(extra) self._installer.extras(extras) diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index 615d8236353..a8a1017b9db 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -29,6 +29,8 @@ [tool.poetry.dependencies] python = "~2.7 || ^3.4" +fizz = { version = "^1.0", optional = true } +buzz = { version = "^2.0", optional = true } [tool.poetry.group.foo.dependencies] foo = "^1.0" @@ -47,6 +49,10 @@ [tool.poetry.group.bam.dependencies] bam = "^1.4" + +[tool.poetry.extras] +extras_a = [ "fizz" ] +extras_b = [ "buzz" ] """ @@ -130,3 +136,37 @@ def test_sync_option_is_passed_to_the_installer( tester.execute("--sync") assert tester.command.installer._requires_synchronization + + +def test_no_all_extras_doesnt_populate_installer( + tester: CommandTester, mocker: MockerFixture +): + """ + Not passing --all-extras means the installer doesn't see any extras. + """ + mocker.patch.object(tester.command.installer, "run", return_value=1) + + tester.execute() + + assert not tester.command.installer._extras + + +def test_all_extras_populates_installer(tester: CommandTester, mocker: MockerFixture): + """ + The --all-extras option results in extras passed to the installer. + """ + mocker.patch.object(tester.command.installer, "run", return_value=1) + + tester.execute("--all-extras") + + assert tester.command.installer._extras == ["extras_a", "extras_b"] + + +def test_extras_conlicts_all_extras(tester: CommandTester, mocker: MockerFixture): + """ + The --extras doesn't make sense with --all-extras. + """ + mocker.patch.object(tester.command.installer, "run", return_value=1) + + with pytest.raises(ValueError): + tester.execute("--extras foo --all-extras") From 9305d355b9a886e71e77fc7e883baec92e610566 Mon Sep 17 00:00:00 2001 From: Kyle Roeschley Date: Thu, 14 Apr 2022 17:15:09 -0500 Subject: [PATCH 2/7] Update docs for install --all-extras --- docs/cli.md | 5 ++++- docs/pyproject.md | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/cli.md b/docs/cli.md index 7675504a834..d579eeb7a8e 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -186,11 +186,13 @@ poetry install --only dev ``` You can also specify the extras you want installed -by passing the `-E|--extras` option (See [Extras]({{< relref "pyproject#extras" >}}) for more info) +by passing the `-E|--extras` option (See [Extras]({{< relref "pyproject#extras" >}}) for more info). +Pass `--all-extras` to install all defined extras for a project. ```bash poetry install --extras "mysql pgsql" poetry install -E mysql -E pgsql +poetry install --all-extras ``` By default `poetry` will install your project's package every time you run `install`: @@ -223,6 +225,7 @@ option is used. * `--no-root`: Do not install the root package (your project). * `--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). * `--no-dev`: Do not install dev dependencies. (**Deprecated**) * `--dev-only`: Only install dev dependencies. (**Deprecated**) * `--remove-untracked`: Remove dependencies not presented in the lock file. (**Deprecated**) diff --git a/docs/pyproject.md b/docs/pyproject.md index 9147294f441..5f2ab2d2971 100644 --- a/docs/pyproject.md +++ b/docs/pyproject.md @@ -306,6 +306,12 @@ poetry install --extras "mysql pgsql" poetry install -E mysql -E pgsql ``` +Or, you can install all extras with the `--all-extras` option: + +```bash +poetry install --all-extras +``` + When installing or specifying Poetry-built packages, the extras defined in this section can be activated as described in [PEP 508](https://www.python.org/dev/peps/pep-0508/#extras). From d6976c489a0edddce7cb603d503a48703c68a223 Mon Sep 17 00:00:00 2001 From: Kyle Roeschley Date: Mon, 18 Apr 2022 11:58:31 -0500 Subject: [PATCH 3/7] Use line.error instead of ValueError on --extras with --all-extras --- src/poetry/console/commands/install.py | 7 +++++-- tests/console/commands/test_install.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py index a724a83401d..e925ac0dcd5 100644 --- a/src/poetry/console/commands/install.py +++ b/src/poetry/console/commands/install.py @@ -81,9 +81,12 @@ def handle(self) -> int: ) if self.option("extras") and self.option("all-extras"): - raise ValueError( - "You cannot specify explicit extras while installing all extras" + self.line_error( + "You cannot specify explicit" + " `--extras` while installing" + " `--all-extras`." ) + return 1 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 a8a1017b9db..c4634b4621c 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -166,7 +166,12 @@ def test_extras_conlicts_all_extras(tester: CommandTester, mocker: MockerFixture """ The --extras doesn't make sense with --all-extras. """ - mocker.patch.object(tester.command.installer, "run", return_value=1) + mocker.patch.object(tester.command.installer, "run", return_value=0) - with pytest.raises(ValueError): - tester.execute("--extras foo --all-extras") + tester.execute("--extras foo --all-extras") + + assert tester.status_code == 1 + assert ( + tester.io.fetch_error() + == "You cannot specify explicit `--extras` while installing `--all-extras`.\n" + ) From 0182965de3d06bf1165efc2b9883d31aa1eda758 Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Sat, 4 Jun 2022 00:21:53 -0600 Subject: [PATCH 4/7] Update src/poetry/console/commands/install.py --- src/poetry/console/commands/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py index e925ac0dcd5..dc3f98a22a9 100644 --- a/src/poetry/console/commands/install.py +++ b/src/poetry/console/commands/install.py @@ -84,7 +84,7 @@ def handle(self) -> int: self.line_error( "You cannot specify explicit" " `--extras` while installing" - " `--all-extras`." + " `using --all-extras`." ) return 1 From 09b93b818ff547438167fa4adaceb43ddae3f481 Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Sat, 4 Jun 2022 00:27:19 -0600 Subject: [PATCH 5/7] Update tests/console/commands/test_install.py --- tests/console/commands/test_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index e0685e69923..e88cdd770d3 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -175,5 +175,5 @@ def test_extras_conlicts_all_extras(tester: CommandTester, mocker: MockerFixture assert tester.status_code == 1 assert ( tester.io.fetch_error() - == "You cannot specify explicit `--extras` while installing `--all-extras`.\n" + == "You cannot specify explicit `--extras` while installing using `--all-extras`.\n" ) From 0fe3679ca1494871f39e8210ccb0a3d53e057dba Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Sat, 4 Jun 2022 00:31:22 -0600 Subject: [PATCH 6/7] Update src/poetry/console/commands/install.py --- src/poetry/console/commands/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py index bb78475c924..e2776d4e004 100644 --- a/src/poetry/console/commands/install.py +++ b/src/poetry/console/commands/install.py @@ -84,7 +84,7 @@ def handle(self) -> int: self.line_error( "You cannot specify explicit" " `--extras` while installing" - " `using --all-extras`." + " using `--all-extras`." ) return 1 From a7a316af9198463d22db4536afa8d33fa008c394 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Jun 2022 06:37:01 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/console/commands/test_install.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index e88cdd770d3..2be8a4a5e3c 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -175,5 +175,6 @@ def test_extras_conlicts_all_extras(tester: CommandTester, mocker: MockerFixture assert tester.status_code == 1 assert ( tester.io.fetch_error() - == "You cannot specify explicit `--extras` while installing using `--all-extras`.\n" + == "You cannot specify explicit `--extras` while installing using" + " `--all-extras`.\n" )