Skip to content

Commit

Permalink
Add a '--all-extras' option
Browse files Browse the repository at this point in the history
  • Loading branch information
pouillon committed Oct 19, 2023
1 parent 33a406f commit 7b50952
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
30 changes: 21 additions & 9 deletions src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
"<error>You cannot specify explicit"
" `<fg=yellow;options=bold>--extras</>` while exporting"
" using `<fg=yellow;options=bold>--all-extras</>`.</error>"
)
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))
Expand Down
7 changes: 7 additions & 0 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7b50952

Please sign in to comment.