Skip to content

Commit

Permalink
Add an all-groups option to export such that export will handle expor…
Browse files Browse the repository at this point in the history
…ting all groups (#294)

Co-authored-by: KotlinIsland <[email protected]>
Co-authored-by: Randy Döring <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2024
1 parent c672530 commit 3610df5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
22 changes: 20 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 dependency groups"),
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,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(
"<error>You cannot specify explicit"
" `<fg=yellow;options=bold>--with</>`, "
"`<fg=yellow;options=bold>--without</>`, "
"or `<fg=yellow;options=bold>--only</>` "
"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
21 changes: 21 additions & 0 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3610df5

Please sign in to comment.