Skip to content

Commit

Permalink
add 'all' and 'all-extras' options
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Aug 29, 2022
1 parent 1faf611 commit 8426891
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class ExportCommand(InstallerCommand):
None,
"Include development dependencies. (<warning>Deprecated</warning>)",
),
option(
"all",
None,
"Include all groups and extras",
),
option(
"all-extras",
None,
"Include all extras",
),
*InstallerCommand._group_dependency_options(),
option(
"extras",
Expand Down Expand Up @@ -82,6 +92,8 @@ def handle(self) -> None:
"</warning>"
)

groups = self.activated_groups

# Checking extras
extras = {
extra for extra_opt in self.option("extras") for extra in extra_opt.split()
Expand All @@ -92,8 +104,19 @@ def handle(self) -> None:
f"Extra [{', '.join(sorted(invalid_extras))}] is not specified."
)

# handle 'all'
if self.option("all"):
extras = set(self.poetry.package.extras.keys())
groups = self.poetry.package.dependency_group_names(include_optional=True)

# handle 'all-extras'
if self.option("all-extras"):
if self.option("extras"):
raise ValueError("Can't have --all-extras and --extras together.")
extras = set(self.poetry.package.extras.keys())

exporter = Exporter(self.poetry)
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
28 changes: 28 additions & 0 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,34 @@ def test_export_reports_invalid_extras(tester: CommandTester, do_lock: None) ->
assert str(error.value) == expected


def test_all_option(tester: CommandTester, do_lock: None) -> None:
tester.execute("--all")
expected = f"""\
bar==1.1.0 ; {MARKER_PY}
baz==2.0.0 ; {MARKER_PY}
foo==1.0.0 ; {MARKER_PY}
opt==2.2.0 ; {MARKER_PY}
qux==1.2.0 ; {MARKER_PY}
"""
assert tester.io.fetch_output() == expected


def test_all_extras_option(tester: CommandTester, do_lock: None) -> None:
tester.execute("--all-extras")
expected = f"""\
bar==1.1.0 ; {MARKER_PY}
foo==1.0.0 ; {MARKER_PY}
qux==1.2.0 ; {MARKER_PY}
"""
assert tester.io.fetch_output() == expected


def test_all_extras_and_extras(tester: CommandTester, do_lock: None) -> None:
with pytest.raises(ValueError) as error:
tester.execute("--all-extras --extras 'feature_bar'")
assert str(error.value) == "Can't have --all-extras and --extras together."


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

0 comments on commit 8426891

Please sign in to comment.