Commit 7ab06997 by kroeschl Committed by GitHub

feat: poetry install --all-extras (#5452)

Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
parent 3353dfd9
...@@ -190,11 +190,13 @@ poetry install --only dev ...@@ -190,11 +190,13 @@ poetry install --only dev
``` ```
You can also specify the extras you want installed 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 ```bash
poetry install --extras "mysql pgsql" poetry install --extras "mysql pgsql"
poetry install -E mysql -E 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`: By default `poetry` will install your project's package every time you run `install`:
...@@ -227,6 +229,7 @@ option is used. ...@@ -227,6 +229,7 @@ option is used.
* `--no-root`: Do not install the root package (your project). * `--no-root`: Do not install the root package (your project).
* `--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). * `--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**) * `--no-dev`: Do not install dev dependencies. (**Deprecated**)
* `--dev-only`: Only install dev dependencies. (**Deprecated**) * `--dev-only`: Only install dev dependencies. (**Deprecated**)
* `--remove-untracked`: Remove dependencies not presented in the lock file. (**Deprecated**) * `--remove-untracked`: Remove dependencies not presented in the lock file. (**Deprecated**)
......
...@@ -384,6 +384,12 @@ poetry install --extras "mysql pgsql" ...@@ -384,6 +384,12 @@ poetry install --extras "mysql pgsql"
poetry install -E mysql -E 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 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). as described in [PEP 508](https://www.python.org/dev/peps/pep-0508/#extras).
......
...@@ -52,6 +52,7 @@ class InstallCommand(InstallerCommand): ...@@ -52,6 +52,7 @@ class InstallCommand(InstallerCommand):
flag=False, flag=False,
multiple=True, multiple=True,
), ),
option("all-extras", None, "Install all extra dependencies."),
] ]
help = """The <info>install</info> command reads the <comment>poetry.lock</> file from help = """The <info>install</info> command reads the <comment>poetry.lock</> file from
...@@ -79,12 +80,23 @@ dependencies and not including the current project, run the command with the ...@@ -79,12 +80,23 @@ dependencies and not including the current project, run the command with the
self.poetry.config.get("experimental.new-installer", False) self.poetry.config.get("experimental.new-installer", False)
) )
extras = [] if self.option("extras") and self.option("all-extras"):
for extra in self.option("extras", []): self.line_error(
if " " in extra: "<error>You cannot specify explicit"
extras += [e.strip() for e in extra.split(" ")] " `<fg=yellow;options=bold>--extras</>` while installing"
else: " using `<fg=yellow;options=bold>--all-extras</>`.</error>"
extras.append(extra) )
return 1
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) self._installer.extras(extras)
......
...@@ -30,6 +30,8 @@ readme = "README.rst" ...@@ -30,6 +30,8 @@ readme = "README.rst"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "~2.7 || ^3.4" python = "~2.7 || ^3.4"
fizz = { version = "^1.0", optional = true }
buzz = { version = "^2.0", optional = true }
[tool.poetry.group.foo.dependencies] [tool.poetry.group.foo.dependencies]
foo = "^1.0" foo = "^1.0"
...@@ -48,6 +50,10 @@ optional = true ...@@ -48,6 +50,10 @@ optional = true
[tool.poetry.group.bam.dependencies] [tool.poetry.group.bam.dependencies]
bam = "^1.4" bam = "^1.4"
[tool.poetry.extras]
extras_a = [ "fizz" ]
extras_b = [ "buzz" ]
""" """
...@@ -132,3 +138,43 @@ def test_sync_option_is_passed_to_the_installer( ...@@ -132,3 +138,43 @@ def test_sync_option_is_passed_to_the_installer(
tester.execute("--sync") tester.execute("--sync")
assert tester.command.installer._requires_synchronization 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=0)
tester.execute("--extras foo --all-extras")
assert tester.status_code == 1
assert (
tester.io.fetch_error()
== "You cannot specify explicit `--extras` while installing using"
" `--all-extras`.\n"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment