diff --git a/README.md b/README.md index 000d92e..7f3d1c6 100644 --- a/README.md +++ b/README.md @@ -51,5 +51,6 @@ poetry export -f requirements.txt --output requirements.txt * `--dev`: Include development dependencies. (**Deprecated**) * `--extras (-E)`: Extra sets of dependencies to include. * `--all-extras`: Include all sets of extra dependencies. +* `--all-groups`: Include all dependency groups. * `--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 0837c86..3b766eb 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -74,5 +74,6 @@ poetry export --only test,docs * {{< 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. +* `--all-groups`: Include all dependency groups. * `--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 06ca162..ec97c5d 100644 --- a/src/poetry_plugin_export/command.py +++ b/src/poetry_plugin_export/command.py @@ -42,6 +42,7 @@ class ExportCommand(GroupCommand): "Include development dependencies. (Deprecated)", ), *GroupCommand._group_dependency_options(), + option("all-groups", None, "Include all dependency groups"), option( "extras", "E", @@ -92,7 +93,6 @@ def handle(self) -> int: "" ) - # Checking extras if self.option("extras") and self.option("all-extras"): self.line_error( "You cannot specify explicit" @@ -116,8 +116,26 @@ def handle(self) -> int: f"Extra [{', '.join(sorted(invalid_extras))}] is not specified." ) + if ( + self.option("with") or self.option("without") or self.option("only") + ) and self.option("all-groups"): + self.line_error( + "You cannot specify explicit" + " `--with`, " + "`--without`, " + "or `--only` " + "while exporting using `--all-groups`." + ) + return 1 + + groups = ( + self.poetry.package.dependency_group_names(include_optional=True) + if self.option("all-groups") + else self.activated_groups + ) + exporter = Exporter(self.poetry, self.io) - exporter.only_groups(list(self.activated_groups)) + exporter.only_groups(list(groups)) exporter.with_extras(list(extras)) exporter.with_hashes(not self.option("without-hashes")) exporter.with_credentials(self.option("with-credentials")) diff --git a/tests/command/test_command_export.py b/tests/command/test_command_export.py index 5951d66..b15ee2b 100644 --- a/tests/command/test_command_export.py +++ b/tests/command/test_command_export.py @@ -237,6 +237,27 @@ def test_extras_conflicts_all_extras(tester: CommandTester, do_lock: None) -> No ) +def test_export_with_all_groups(tester: CommandTester, do_lock: None) -> None: + tester.execute("--format requirements.txt --all-groups") + output = tester.io.fetch_output() + assert f"baz==2.0.0 ; {MARKER_PY}" in output + assert f"opt==2.2.0 ; {MARKER_PY}" in output + + +@pytest.mark.parametrize("flag", ["--with", "--without", "--only"]) +def test_with_conflicts_all_groups( + tester: CommandTester, do_lock: None, flag: str +) -> None: + tester.execute(f"{flag}=bar --all-groups") + + assert tester.status_code == 1 + assert ( + "You cannot specify explicit `--with`, `--without`," + " or `--only` while exporting using `--all-groups`.\n" + in tester.io.fetch_error() + ) + + def test_export_with_urls( monkeypatch: MonkeyPatch, tester: CommandTester, poetry: Poetry ) -> None: