Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an all-groups option to export such that export will handle exporting all groups #294

Merged
merged 8 commits into from
Sep 1, 2024
18 changes: 16 additions & 2 deletions src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ExportCommand(GroupCommand):
"Include development dependencies. (<warning>Deprecated</warning>)",
),
*GroupCommand._group_dependency_options(),
option("all-groups", None, "Include all sets of extra groups"),
radoering marked this conversation as resolved.
Show resolved Hide resolved
option(
"extras",
"E",
Expand Down Expand Up @@ -92,7 +93,6 @@ def handle(self) -> int:
"</warning>"
)

# Checking extras
if self.option("extras") and self.option("all-extras"):
self.line_error(
"<error>You cannot specify explicit"
Expand All @@ -116,8 +116,22 @@ def handle(self) -> int:
f"Extra [{', '.join(sorted(invalid_extras))}] is not specified."
)

if self.option("with") and self.option("all-groups"):
self.line_error(
"<error>You cannot specify explicit"
" `<fg=yellow;options=bold>--with</>` while exporting"
" using `<fg=yellow;options=bold>--all-groups</>`.</error>"
)
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"))
Expand Down
17 changes: 17 additions & 0 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ 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


def test_with_conflicts_all_groups(tester: CommandTester, do_lock: None) -> None:
tester.execute("--with=bar --all-groups")

assert tester.status_code == 1
assert (
"You cannot specify explicit `--with` while exporting using `--all-groups`.\n"
in tester.io.fetch_error()
)


def test_export_with_urls(
monkeypatch: MonkeyPatch, tester: CommandTester, poetry: Poetry
) -> None:
Expand Down
Loading