diff --git a/docs/cli.md b/docs/cli.md
index 42bfb181fc4..fb94f416ce1 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -164,6 +164,12 @@ You can also select optional dependency groups with the `--with` option.
poetry install --with test,docs
```
+To install all dependency groups including the optional groups, use the ``--all-groups`` flag.
+
+```bash
+poetry install --all-groups
+```
+
It's also possible to only install specific dependency groups by using the `only` option.
```bash
@@ -254,9 +260,10 @@ poetry install --compile
* `--sync`: Synchronize the environment with the locked packages and the specified groups.
* `--no-root`: Do not install the root package (your project).
* `--no-directory`: Skip all directory path dependencies (including transitive ones).
-* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
+* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`).
* `--extras (-E)`: Features to install (multiple values allowed).
-* `--all-extras`: Install all extra features (conflicts with --extras).
+* `--all-extras`: Install all extra features (conflicts with `--extras`).
+* `--all-groups`: Install dependencies from all groups (conflicts with `--only`, `--with`, and `--without`).
* `--compile`: Compile Python source files to bytecode.
* `--remove-untracked`: Remove dependencies not presented in the lock file. (**Deprecated**, use `--sync` instead)
@@ -295,7 +302,7 @@ You can do this using the `add` command.
* `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include.
* `--only`: The only dependency groups to include.
-* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose).
+* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables `--verbose`).
* `--lock` : Do not perform install (only update the lockfile).
* `--sync`: Synchronize the environment with the locked packages and the specified groups.
@@ -456,7 +463,7 @@ about dependency groups.
* `--platform`: Platforms for which the dependency must be installed.
* `--source`: Name of the source to use to install the package.
* `--allow-prereleases`: Accept prereleases.
-* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
+* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`).
* `--lock`: Do not perform install (only update the lockfile).
@@ -482,7 +489,7 @@ about dependency groups.
* `--group (-G)`: The group to remove the dependency from.
* `--dev (-D)`: Removes a package from the development dependencies. (shortcut for `-G dev`)
-* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose).
+* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables `--verbose`).
* `--lock`: Do not perform operations (only update the lockfile).
@@ -991,7 +998,7 @@ poetry self add artifacts-keyring
* `--extras (-E)`: Extras to activate for the dependency. (multiple values allowed)
* `--allow-prereleases`: Accept prereleases.
* `--source`: Name of the source to use to install the package.
-* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
+* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`).
### self update
@@ -1009,7 +1016,7 @@ poetry self update
#### Options
* `--preview`: Allow the installation of pre-release versions.
-* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
+* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`).
### self lock
@@ -1063,7 +1070,7 @@ poetry self remove poetry-plugin-export
#### Options
-* `--dry-run`: Outputs the operations but will not execute anything (implicitly enables --verbose).
+* `--dry-run`: Outputs the operations but will not execute anything (implicitly enables `--verbose`).
### self install
@@ -1082,4 +1089,4 @@ poetry self install --sync
#### Options
* `--sync`: Synchronize the environment with the locked packages and the specified groups.
-* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
+* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`).
diff --git a/src/poetry/console/commands/group_command.py b/src/poetry/console/commands/group_command.py
index f2ec9fbe52c..06dea92cc78 100644
--- a/src/poetry/console/commands/group_command.py
+++ b/src/poetry/console/commands/group_command.py
@@ -79,6 +79,12 @@ def activated_groups(self) -> set[str]:
for groups in self.option(key, "")
for group in groups.split(",")
}
+
+ if self.option("all-groups"):
+ groups["with"] = self.poetry.package.dependency_group_names(
+ include_optional=True
+ )
+
self._validate_group_options(groups)
if groups["only"] and (groups["with"] or groups["without"]):
diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py
index 4c7c7d24153..972d04d8f77 100644
--- a/src/poetry/console/commands/install.py
+++ b/src/poetry/console/commands/install.py
@@ -50,6 +50,7 @@ class InstallCommand(InstallerCommand):
multiple=True,
),
option("all-extras", None, "Install all extra dependencies."),
+ option("all-groups", None, "Install dependencies from all groups."),
option("only-root", None, "Exclude all dependencies."),
option(
"compile",
@@ -104,12 +105,14 @@ def handle(self) -> int:
return 1
if self.option("only-root") and any(
- self.option(key) for key in {"with", "without", "only"}
+ self.option(key) for key in {"with", "without", "only", "all-groups"}
):
self.line_error(
"The `--with>`,"
- " `--without>` and"
- " `--only>` options cannot be used with"
+ " `--without>`,"
+ " `--only>` and"
+ " `--all-groups>`"
+ " options cannot be used with"
" the `--only-root>`"
" option."
)
@@ -122,6 +125,17 @@ def handle(self) -> int:
)
return 1
+ if (
+ self.option("only") or self.option("with") or self.option("without")
+ ) and self.option("all-groups"):
+ self.line_error(
+ "You cannot specify `--with>`,"
+ " `--without>`, or"
+ " `--only>` when using"
+ " `--all-groups>`."
+ )
+ return 1
+
extras: list[str]
if self.option("all-extras"):
extras = list(self.poetry.package.extras.keys())
diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py
index 85162a31e5e..ae163df3ec2 100644
--- a/tests/console/commands/test_install.py
+++ b/tests/console/commands/test_install.py
@@ -104,6 +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"}),
# net result zero options
("--with foo", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
("--without bam", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
@@ -285,9 +286,10 @@ def test_extras_conflicts_all_extras(
"--without foo",
"--with foo,bar --without baz",
"--only foo",
+ "--all-groups",
],
)
-def test_only_root_conflicts_with_without_only(
+def test_only_root_conflicts_with_without_only_all_groups(
options: str,
tester: CommandTester,
mocker: MockerFixture,
@@ -300,11 +302,37 @@ def test_only_root_conflicts_with_without_only(
assert tester.status_code == 1
assert (
tester.io.fetch_error()
- == "The `--with`, `--without` and `--only` options cannot be used with"
+ == "The `--with`, `--without`, `--only` and `--all-groups` options cannot be used with"
" the `--only-root` option.\n"
)
+@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(f"{options} --all-groups")
+
+ assert tester.status_code == 1
+ assert (
+ tester.io.fetch_error()
+ == "You cannot specify `--with`, `--without`, or `--only` when using `--all-groups`.\n"
+ )
+
+
@pytest.mark.parametrize(
("options", "valid_groups", "should_raise"),
[