diff --git a/README.md b/README.md index e9ffb20..000d92e 100644 --- a/README.md +++ b/README.md @@ -50,5 +50,6 @@ poetry export -f requirements.txt --output requirements.txt * `--default`: Only export the main dependencies. (**Deprecated**) * `--dev`: Include development dependencies. (**Deprecated**) * `--extras (-E)`: Extra sets of dependencies to include. +* `--all-extras`: Include all sets of extra dependencies. * `--without-hashes`: Exclude hashes from the exported file. * `--with-credentials`: Include credentials for extra indices. diff --git a/docs/_index.md b/docs/_index.md index cd34c3d..0837c86 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -73,5 +73,6 @@ poetry export --only test,docs * `--default`: Only export the main dependencies. (**Deprecated**) * {{< option name="dev" deprecated=true >}}Include development dependencies.{{< /option >}} * `--extras (-E)`: Extra sets of dependencies to include. +* `--all-extras`: Include all sets of extra dependencies. * `--without-hashes`: Exclude hashes from the exported file. * `--with-credentials`: Include credentials for extra indices. diff --git a/src/poetry_plugin_export/command.py b/src/poetry_plugin_export/command.py index 854493f..abb4ff6 100644 --- a/src/poetry_plugin_export/command.py +++ b/src/poetry_plugin_export/command.py @@ -44,6 +44,7 @@ class ExportCommand(GroupCommand): multiple=True, ), option("with-credentials", None, "Include credentials for extra indices."), + option("all-extras", None, "Include all sets of extra dependencies."), ] @property @@ -86,16 +87,27 @@ def handle(self) -> int: ) # Checking extras - extras = { - canonicalize_name(extra) - for extra_opt in self.option("extras") - for extra in extra_opt.split() - } - invalid_extras = extras - self.poetry.package.extras.keys() - if invalid_extras: - raise ValueError( - f"Extra [{', '.join(sorted(invalid_extras))}] is not specified." + if self.option("extras") and self.option("all-extras"): + self.line_error( + "You cannot specify explicit" + " `--extras` while exporting" + " using `--all-extras`." ) + return 1 + + if self.option("all-extras"): + extras = self.poetry.package.extras.keys() + else: + extras = { + canonicalize_name(extra) + for extra_opt in self.option("extras") + for extra in extra_opt.split() + } + invalid_extras = extras - self.poetry.package.extras.keys() + if invalid_extras: + raise ValueError( + f"Extra [{', '.join(sorted(invalid_extras))}] is not specified." + ) exporter = Exporter(self.poetry, self.io) exporter.only_groups(list(self.activated_groups)) diff --git a/tests/command/test_command_export.py b/tests/command/test_command_export.py index 6f37fe3..5757e26 100644 --- a/tests/command/test_command_export.py +++ b/tests/command/test_command_export.py @@ -220,6 +220,13 @@ def test_export_reports_invalid_extras(tester: CommandTester, do_lock: None) -> assert str(error.value) == expected +def test_export_with_all_extras(tester: CommandTester, do_lock: None) -> None: + tester.execute("--format requirements.txt --all-extras") + output = tester.io.fetch_output() + assert f"bar==1.1.0 ; {MARKER_PY}" in output + assert f"qux==1.2.0 ; {MARKER_PY}" in output + + def test_export_with_urls( monkeypatch: MonkeyPatch, tester: CommandTester, poetry: Poetry ) -> None: