Skip to content

Commit 7b50952

Browse files
committed
Add a '--all-extras' option
1 parent 33a406f commit 7b50952

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

README.md

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

docs/_index.md

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

src/poetry_plugin_export/command.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ExportCommand(GroupCommand):
4444
multiple=True,
4545
),
4646
option("with-credentials", None, "Include credentials for extra indices."),
47+
option("all-extras", None, "Include all sets of extra dependencies."),
4748
]
4849

4950
@property
@@ -86,16 +87,27 @@ def handle(self) -> int:
8687
)
8788

8889
# Checking extras
89-
extras = {
90-
canonicalize_name(extra)
91-
for extra_opt in self.option("extras")
92-
for extra in extra_opt.split()
93-
}
94-
invalid_extras = extras - self.poetry.package.extras.keys()
95-
if invalid_extras:
96-
raise ValueError(
97-
f"Extra [{', '.join(sorted(invalid_extras))}] is not specified."
90+
if self.option("extras") and self.option("all-extras"):
91+
self.line_error(
92+
"<error>You cannot specify explicit"
93+
" `<fg=yellow;options=bold>--extras</>` while exporting"
94+
" using `<fg=yellow;options=bold>--all-extras</>`.</error>"
9895
)
96+
return 1
97+
98+
if self.option("all-extras"):
99+
extras = self.poetry.package.extras.keys()
100+
else:
101+
extras = {
102+
canonicalize_name(extra)
103+
for extra_opt in self.option("extras")
104+
for extra in extra_opt.split()
105+
}
106+
invalid_extras = extras - self.poetry.package.extras.keys()
107+
if invalid_extras:
108+
raise ValueError(
109+
f"Extra [{', '.join(sorted(invalid_extras))}] is not specified."
110+
)
99111

100112
exporter = Exporter(self.poetry, self.io)
101113
exporter.only_groups(list(self.activated_groups))

tests/command/test_command_export.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ def test_export_reports_invalid_extras(tester: CommandTester, do_lock: None) ->
220220
assert str(error.value) == expected
221221

222222

223+
def test_export_with_all_extras(tester: CommandTester, do_lock: None) -> None:
224+
tester.execute("--format requirements.txt --all-extras")
225+
output = tester.io.fetch_output()
226+
assert f"bar==1.1.0 ; {MARKER_PY}" in output
227+
assert f"qux==1.2.0 ; {MARKER_PY}" in output
228+
229+
223230
def test_export_with_urls(
224231
monkeypatch: MonkeyPatch, tester: CommandTester, poetry: Poetry
225232
) -> None:

0 commit comments

Comments
 (0)