Skip to content

Commit 3610df5

Browse files
JiafiKotlinIslandradoering
authored
Add an all-groups option to export such that export will handle exporting all groups (#294)
Co-authored-by: KotlinIsland <kotlinisland@users.noreply.github.com> Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
1 parent c672530 commit 3610df5

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ poetry export -f requirements.txt --output requirements.txt
5151
* `--dev`: Include development dependencies. (**Deprecated**)
5252
* `--extras (-E)`: Extra sets of dependencies to include.
5353
* `--all-extras`: Include all sets of extra dependencies.
54+
* `--all-groups`: Include all dependency groups.
5455
* `--without-hashes`: Exclude hashes from the exported file.
5556
* `--with-credentials`: Include credentials for extra indices.

docs/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ poetry export --only test,docs
7474
* {{< option name="dev" deprecated=true >}}Include development dependencies.{{< /option >}}
7575
* `--extras (-E)`: Extra sets of dependencies to include.
7676
* `--all-extras`: Include all sets of extra dependencies.
77+
* `--all-groups`: Include all dependency groups.
7778
* `--without-hashes`: Exclude hashes from the exported file.
7879
* `--with-credentials`: Include credentials for extra indices.

src/poetry_plugin_export/command.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ExportCommand(GroupCommand):
4242
"Include development dependencies. (<warning>Deprecated</warning>)",
4343
),
4444
*GroupCommand._group_dependency_options(),
45+
option("all-groups", None, "Include all dependency groups"),
4546
option(
4647
"extras",
4748
"E",
@@ -92,7 +93,6 @@ def handle(self) -> int:
9293
"</warning>"
9394
)
9495

95-
# Checking extras
9696
if self.option("extras") and self.option("all-extras"):
9797
self.line_error(
9898
"<error>You cannot specify explicit"
@@ -116,8 +116,26 @@ def handle(self) -> int:
116116
f"Extra [{', '.join(sorted(invalid_extras))}] is not specified."
117117
)
118118

119+
if (
120+
self.option("with") or self.option("without") or self.option("only")
121+
) and self.option("all-groups"):
122+
self.line_error(
123+
"<error>You cannot specify explicit"
124+
" `<fg=yellow;options=bold>--with</>`, "
125+
"`<fg=yellow;options=bold>--without</>`, "
126+
"or `<fg=yellow;options=bold>--only</>` "
127+
"while exporting using `<fg=yellow;options=bold>--all-groups</>`.</error>"
128+
)
129+
return 1
130+
131+
groups = (
132+
self.poetry.package.dependency_group_names(include_optional=True)
133+
if self.option("all-groups")
134+
else self.activated_groups
135+
)
136+
119137
exporter = Exporter(self.poetry, self.io)
120-
exporter.only_groups(list(self.activated_groups))
138+
exporter.only_groups(list(groups))
121139
exporter.with_extras(list(extras))
122140
exporter.with_hashes(not self.option("without-hashes"))
123141
exporter.with_credentials(self.option("with-credentials"))

tests/command/test_command_export.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,27 @@ def test_extras_conflicts_all_extras(tester: CommandTester, do_lock: None) -> No
237237
)
238238

239239

240+
def test_export_with_all_groups(tester: CommandTester, do_lock: None) -> None:
241+
tester.execute("--format requirements.txt --all-groups")
242+
output = tester.io.fetch_output()
243+
assert f"baz==2.0.0 ; {MARKER_PY}" in output
244+
assert f"opt==2.2.0 ; {MARKER_PY}" in output
245+
246+
247+
@pytest.mark.parametrize("flag", ["--with", "--without", "--only"])
248+
def test_with_conflicts_all_groups(
249+
tester: CommandTester, do_lock: None, flag: str
250+
) -> None:
251+
tester.execute(f"{flag}=bar --all-groups")
252+
253+
assert tester.status_code == 1
254+
assert (
255+
"You cannot specify explicit `--with`, `--without`,"
256+
" or `--only` while exporting using `--all-groups`.\n"
257+
in tester.io.fetch_error()
258+
)
259+
260+
240261
def test_export_with_urls(
241262
monkeypatch: MonkeyPatch, tester: CommandTester, poetry: Poetry
242263
) -> None:

0 commit comments

Comments
 (0)