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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading