Skip to content

Commit

Permalink
refactor: make --all-groups conflict with --only, --without and…
Browse files Browse the repository at this point in the history
… `--with`
  • Loading branch information
schneebuzz committed Oct 13, 2024
1 parent e3190cf commit b5e7c98
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
6 changes: 0 additions & 6 deletions src/poetry/console/commands/group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ def activated_groups(self) -> set[str]:
}

if self.option("all-groups"):
if self.option("with"):
self.line_error(
"<warning>The `<fg=yellow;options=bold>--with</>` option is"
" ignored when using the `<fg=yellow;options=bold>--all-groups</>`"
" option.</warning>"
)
groups["with"] = self.poetry.package.dependency_group_names(
include_optional=True
)
Expand Down
10 changes: 7 additions & 3 deletions src/poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ def handle(self) -> int:
)
return 1

if self.option("only") and self.option("all-groups"):
if (
self.option("only") or self.option("with") or self.option("without")
) and self.option("all-groups"):
self.line_error(
"<error>You cannot specify `<fg=yellow;options=bold>--all-groups</>`"
" when using `<fg=yellow;options=bold>--only</>`.</error>"
"<error>You cannot specify `<fg=yellow;options=bold>--with</>`,"
" `<fg=yellow;options=bold>--without</>`, or"
" `<fg=yellow;options=bold>--only</>` when using"
" `<fg=yellow;options=bold>--all-groups</>`.</error>"
)
return 1

Expand Down
29 changes: 14 additions & 15 deletions tests/console/commands/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@
[tool.poetry.group.bam.dependencies]
bam = "^1.4"
[tool.poetry.group.bum]
optional = true
[tool.poetry.group.bum.dependencies]
bam = "^1.5"
[tool.poetry.extras]
extras_a = [ "fizz" ]
extras_b = [ "buzz" ]
Expand Down Expand Up @@ -110,12 +104,7 @@ def _project_factory(
("--without foo,bar", {MAIN_GROUP, "baz", "bim"}),
(f"--without {MAIN_GROUP}", {"foo", "bar", "baz", "bim"}),
("--with foo,bar --without baz --without bim --only bam", {"bam"}),
("--all-groups", {MAIN_GROUP, "foo", "bar", "baz", "bim", "bam", "bum"}),
(
"--all-groups --with bum",
{MAIN_GROUP, "foo", "bar", "baz", "bim", "bam", "bum"},
),
("--all-groups --without bum", {MAIN_GROUP, "foo", "bar", "baz", "bim", "bam"}),
("--all-groups", {MAIN_GROUP, "foo", "bar", "baz", "bim", "bam"}),
# net result zero options
("--with foo", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
("--without bam", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
Expand Down Expand Up @@ -320,19 +309,29 @@ def test_only_root_conflicts_with_without_only_all_groups(
)


def test_only_conflicts_with_all_groups(
@pytest.mark.parametrize(
"options",
[
"--with foo",
"--without foo",
"--with foo,bar --without baz",
"--only foo",
],
)
def test_all_groups_conflicts_with_only_with_without(
options: str,
tester: CommandTester,
mocker: MockerFixture,
) -> None:
assert isinstance(tester.command, InstallerCommand)
mocker.patch.object(tester.command.installer, "run", return_value=0)

tester.execute("--only foo --all-groups")
tester.execute(f"{options} --all-groups")

assert tester.status_code == 1
assert (
tester.io.fetch_error()
== "You cannot specify `--all-groups` when using `--only`.\n"
== "You cannot specify `--with`, `--without`, or `--only` when using `--all-groups`.\n"
)


Expand Down

0 comments on commit b5e7c98

Please sign in to comment.