From 6beef611ab7a52fae229d00587db3c626d09ec48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Randy=20D=C3=B6ring?=
<30527984+radoering@users.noreply.github.com>
Date: Sun, 17 Apr 2022 14:51:00 +0200
Subject: [PATCH] dependency groups: rename implicit group "default" to "main"
This is done in order to avoid ambiguity between "default group" and "default dependencies" (the groups that are considered by a command by default)
---
docs/cli.md | 10 ++++----
docs/managing-dependencies.md | 10 ++++----
src/poetry/console/commands/add.py | 10 ++++++--
src/poetry/console/commands/group_command.py | 15 +++++++----
src/poetry/console/commands/remove.py | 10 ++++++--
src/poetry/packages/locker.py | 8 +++++-
src/poetry/puzzle/solver.py | 10 ++++++--
tests/console/commands/test_install.py | 27 ++++++++++++--------
tests/console/commands/test_show.py | 12 ++++++---
tests/installation/test_installer.py | 14 +++++++---
tests/puzzle/test_solver.py | 2 +-
11 files changed, 87 insertions(+), 41 deletions(-)
diff --git a/docs/cli.md b/docs/cli.md
index 8d2b4901000..1ce86fcc149 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -218,7 +218,7 @@ option is used.
* `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include.
* `--only`: The only dependency groups to include.
-* `--default`: Only include the default dependencies. (**Deprecated**)
+* `--default`: Only include the main dependencies. (**Deprecated**)
* `--sync`: Synchronize the environment with the locked packages and the specified groups.
* `--no-root`: Do not install the root package (your project).
* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
@@ -258,7 +258,7 @@ update the constraint, for example `^2.3`. You can do this using the `add` comma
* `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include.
* `--only`: The only dependency groups to include.
-* `--default`: Only include the default dependencies. (**Deprecated**)
+* `--default`: Only include the main dependencies. (**Deprecated**)
* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose).
* `--no-dev` : Do not update the development dependencies. (**Deprecated**)
* `--lock` : Do not perform install (only update the lockfile).
@@ -439,7 +439,7 @@ required by
* `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include.
* `--only`: The only dependency groups to include.
-* `--default`: Only include the default dependencies. (**Deprecated**)
+* `--default`: Only include the main dependencies. (**Deprecated**)
* `--no-dev`: Do not list the dev dependencies. (**Deprecated**)
* `--tree`: List the dependencies as a tree.
* `--latest (-l)`: Show the latest version.
@@ -626,7 +626,7 @@ and is also available as a pre-commit hook. See [pre-commit hooks](/docs/pre-com
{{% /note %}}
{{% note %}}
-Unlike the `install` command, this command only includes the project's dependencies defined in the implicit `default`
+Unlike the `install` command, this command only includes the project's dependencies defined in the implicit `main`
group defined in `tool.poetry.dependencies` when used without specifying any options.
{{% /note %}}
@@ -641,7 +641,7 @@ group defined in `tool.poetry.dependencies` when used without specifying any opt
* `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include.
* `--only`: The only dependency groups to include.
-* `--default`: Only include the default dependencies. (**Deprecated**)
+* `--default`: Only include the main dependencies. (**Deprecated**)
* `--without-hashes`: Exclude hashes from the exported file.
* `--without-urls`: Exclude source repository urls from the exported file.
* `--with-credentials`: Include credentials for extra indices.
diff --git a/docs/managing-dependencies.md b/docs/managing-dependencies.md
index fad3fc8bde6..5d0046e17c2 100644
--- a/docs/managing-dependencies.md
+++ b/docs/managing-dependencies.md
@@ -37,10 +37,10 @@ the dependencies logically.
{{% /note %}}
{{% note %}}
-The dependencies declared in `tool.poetry.dependencies` are part of an implicit `default` group.
+The dependencies declared in `tool.poetry.dependencies` are part of an implicit `main` group.
```toml
-[tool.poetry.dependencies] # Default dependency group
+[tool.poetry.dependencies] # main dependency group
httpx = "*"
pendulum = "*"
@@ -115,7 +115,7 @@ If the group does not already exist, it will be created automatically.
`poetry install`.
{{% note %}}
-The default set of dependencies for a project includes the implicit `default` group defined in
+The default set of dependencies for a project includes the implicit `main` group defined in
`tool.poetry.dependencies` as well as all groups that are not explicitly marked as an
[optional group]({{< relref "#optional-groups" >}}).
{{% /note %}}
@@ -151,10 +151,10 @@ poetry install --only docs
{{% note %}}
If you only want to install the project's runtime dependencies, you can do so with the
-`--only default` notation:
+`--only main` notation:
```bash
-poetry install --only default
+poetry install --only main
```
{{% /note %}}
diff --git a/src/poetry/console/commands/add.py b/src/poetry/console/commands/add.py
index 854bcb91803..4748f2653b8 100644
--- a/src/poetry/console/commands/add.py
+++ b/src/poetry/console/commands/add.py
@@ -7,6 +7,12 @@
from cleo.helpers import argument
from cleo.helpers import option
+
+try:
+ from poetry.core.packages.dependency_group import MAIN_GROUP
+except ImportError:
+ MAIN_GROUP = "default"
+
from poetry.console.commands.init import InitCommand
from poetry.console.commands.installer_command import InstallerCommand
@@ -23,7 +29,7 @@ class AddCommand(InstallerCommand, InitCommand):
"-G",
"The group to add the dependency to.",
flag=False,
- default="default",
+ default=MAIN_GROUP,
),
option("dev", "D", "Add as a development dependency."),
option("editable", "e", "Add vcs/path dependencies as editable."),
@@ -111,7 +117,7 @@ def handle(self) -> int:
content = self.poetry.file.read()
poetry_content = content["tool"]["poetry"]
- if group == "default":
+ if group == MAIN_GROUP:
if "dependencies" not in poetry_content:
poetry_content["dependencies"] = table()
diff --git a/src/poetry/console/commands/group_command.py b/src/poetry/console/commands/group_command.py
index 23bf04e3a95..e84a5f72323 100644
--- a/src/poetry/console/commands/group_command.py
+++ b/src/poetry/console/commands/group_command.py
@@ -4,6 +4,12 @@
from cleo.helpers import option
+
+try:
+ from poetry.core.packages.dependency_group import MAIN_GROUP
+except ImportError:
+ MAIN_GROUP = "default"
+
from poetry.console.commands.env_command import EnvCommand
@@ -34,8 +40,7 @@ def _group_dependency_options() -> list[Option]:
option(
"default",
None,
- "Only include the default dependencies."
- " (Deprecated)",
+ "Only include the main dependencies. (Deprecated)",
),
option(
"only",
@@ -67,10 +72,10 @@ def activated_groups(self) -> set[str]:
}
for opt, new, group in [
- ("default", "only", "default"),
- ("no-dev", "only", "default"),
+ ("default", "only", MAIN_GROUP),
+ ("no-dev", "only", MAIN_GROUP),
("dev", "with", "dev"),
- ("dev-only", "without", "default"),
+ ("dev-only", "without", MAIN_GROUP),
]:
if self.io.input.has_option(opt) and self.option(opt):
self.line_error(
diff --git a/src/poetry/console/commands/remove.py b/src/poetry/console/commands/remove.py
index 5a79c9e724d..092dd3f4859 100644
--- a/src/poetry/console/commands/remove.py
+++ b/src/poetry/console/commands/remove.py
@@ -5,6 +5,12 @@
from cleo.helpers import argument
from cleo.helpers import option
+
+try:
+ from poetry.core.packages.dependency_group import MAIN_GROUP
+except ImportError:
+ MAIN_GROUP = "default"
+
from poetry.console.commands.installer_command import InstallerCommand
@@ -55,10 +61,10 @@ def handle(self) -> int:
]
for group_name, section in [
- ("default", poetry_content["dependencies"])
+ (MAIN_GROUP, poetry_content["dependencies"])
] + group_sections:
removed += self._remove_packages(packages, section, group_name)
- if group_name != "default":
+ if group_name != MAIN_GROUP:
if not section:
del poetry_content["group"][group_name]
else:
diff --git a/src/poetry/packages/locker.py b/src/poetry/packages/locker.py
index 80c24a4fb9f..f620a65192d 100644
--- a/src/poetry/packages/locker.py
+++ b/src/poetry/packages/locker.py
@@ -14,6 +14,12 @@
from typing import Sequence
from poetry.core.packages.dependency import Dependency
+
+
+try:
+ from poetry.core.packages.dependency_group import MAIN_GROUP
+except ImportError:
+ MAIN_GROUP = "default"
from poetry.core.packages.package import Package
from poetry.core.semver.helpers import parse_constraint
from poetry.core.semver.version import Version
@@ -121,7 +127,7 @@ def locked_repository(self) -> Repository:
)
package.description = info.get("description", "")
package.category = info.get("category", "main")
- package.groups = info.get("groups", ["default"])
+ package.groups = info.get("groups", [MAIN_GROUP])
package.optional = info["optional"]
if "hashes" in lock_data["metadata"]:
# Old lock so we create dummy files from the hashes
diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py
index 6e2e370050c..47ceaeb9771 100644
--- a/src/poetry/puzzle/solver.py
+++ b/src/poetry/puzzle/solver.py
@@ -10,6 +10,12 @@
from typing import Iterator
from typing import Tuple
+
+try:
+ from poetry.core.packages.dependency_group import MAIN_GROUP
+except ImportError:
+ MAIN_GROUP = "default"
+
from poetry.mixology import resolve_version
from poetry.mixology.failure import SolveFailure
from poetry.packages import DependencyPackage
@@ -270,7 +276,7 @@ def __init__(
self.groups: frozenset[str] = frozenset()
self.optional = True
elif dep:
- self.category = "main" if "default" in dep.groups else "dev"
+ self.category = "main" if MAIN_GROUP in dep.groups else "dev"
self.groups = dep.groups
self.optional = dep.is_optional()
else:
@@ -348,7 +354,7 @@ def aggregate_package_nodes(nodes: list[PackageNode]) -> tuple[Package, int]:
for node in nodes:
groups.extend(node.groups)
- category = "main" if any("default" in node.groups for node in nodes) else "dev"
+ category = "main" if any(MAIN_GROUP in node.groups for node in nodes) else "dev"
optional = all(node.optional for node in nodes)
for node in nodes:
node.depth = depth
diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py
index 615d8236353..a3545ef52c2 100644
--- a/tests/console/commands/test_install.py
+++ b/tests/console/commands/test_install.py
@@ -7,6 +7,11 @@
from poetry.core.masonry.utils.module import ModuleOrPackageNotFound
+try:
+ from poetry.core.packages.dependency_group import MAIN_GROUP
+except ImportError:
+ MAIN_GROUP = "default"
+
if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester
from pytest_mock import MockerFixture
@@ -65,23 +70,23 @@ def tester(
@pytest.mark.parametrize(
("options", "groups"),
[
- ("", {"default", "foo", "bar", "baz", "bim"}),
- ("--only default", {"default"}),
+ ("", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
+ (f"--only {MAIN_GROUP}", {MAIN_GROUP}),
("--only foo", {"foo"}),
("--only foo,bar", {"foo", "bar"}),
("--only bam", {"bam"}),
- ("--with bam", {"default", "foo", "bar", "baz", "bim", "bam"}),
- ("--without foo,bar", {"default", "baz", "bim"}),
- ("--without default", {"foo", "bar", "baz", "bim"}),
+ ("--with bam", {MAIN_GROUP, "foo", "bar", "baz", "bim", "bam"}),
+ ("--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"}),
# net result zero options
- ("--with foo", {"default", "foo", "bar", "baz", "bim"}),
- ("--without bam", {"default", "foo", "bar", "baz", "bim"}),
- ("--with bam --without bam", {"default", "foo", "bar", "baz", "bim"}),
- ("--with foo --without foo", {"default", "bar", "baz", "bim"}),
+ ("--with foo", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
+ ("--without bam", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
+ ("--with bam --without bam", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
+ ("--with foo --without foo", {MAIN_GROUP, "bar", "baz", "bim"}),
# deprecated options
- ("--default", {"default"}),
- ("--no-dev", {"default"}),
+ ("--default", {MAIN_GROUP}),
+ ("--no-dev", {MAIN_GROUP}),
("--dev-only", {"foo", "bar", "baz", "bim"}),
],
)
diff --git a/tests/console/commands/test_show.py b/tests/console/commands/test_show.py
index d5e69b53a01..73a63c7f08e 100644
--- a/tests/console/commands/test_show.py
+++ b/tests/console/commands/test_show.py
@@ -6,6 +6,12 @@
from poetry.core.packages.dependency_group import DependencyGroup
+
+try:
+ from poetry.core.packages.dependency_group import MAIN_GROUP
+except ImportError:
+ MAIN_GROUP = "default"
+
from poetry.factory import Factory
from tests.helpers import get_package
@@ -197,13 +203,13 @@ def _configure_project_with_groups(poetry: Poetry, installed: Repository) -> Non
""",
),
(
- "--without default",
+ f"--without {MAIN_GROUP}",
"""\
pytest 3.7.3 Pytest package
""",
),
(
- "--only default",
+ f"--only {MAIN_GROUP}",
"""\
cachy 0.1.0 Cachy package
""",
@@ -228,7 +234,7 @@ def _configure_project_with_groups(poetry: Poetry, installed: Repository) -> Non
""",
),
(
- "--with time --without default,test",
+ f"--with time --without {MAIN_GROUP},test",
"""\
pendulum 2.0.0 Pendulum package
""",
diff --git a/tests/installation/test_installer.py b/tests/installation/test_installer.py
index b330b46a728..cd065937447 100644
--- a/tests/installation/test_installer.py
+++ b/tests/installation/test_installer.py
@@ -20,6 +20,12 @@
from poetry.core.packages.project_package import ProjectPackage
from poetry.core.toml.file import TOMLFile
+
+try:
+ from poetry.core.packages.dependency_group import MAIN_GROUP
+except ImportError:
+ MAIN_GROUP = "default"
+
from poetry.factory import Factory
from poetry.installation import Installer as BaseInstaller
from poetry.installation.executor import Executor as BaseExecutor
@@ -383,10 +389,10 @@ def _configure_run_install_dev(
([], 0, 0, 3, True),
(["dev"], 1, 0, 0, False),
(["dev"], 0, 0, 2, True),
- (["default"], 2, 0, 0, False),
- (["default"], 0, 0, 1, True),
- (["default", "dev"], 3, 0, 0, False),
- (["default", "dev"], 0, 0, 0, True),
+ ([MAIN_GROUP], 2, 0, 0, False),
+ ([MAIN_GROUP], 0, 0, 1, True),
+ ([MAIN_GROUP, "dev"], 3, 0, 0, False),
+ ([MAIN_GROUP, "dev"], 0, 0, 0, True),
],
)
def test_run_install_with_dependency_groups(
diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py
index bb062fab177..5b904b15666 100644
--- a/tests/puzzle/test_solver.py
+++ b/tests/puzzle/test_solver.py
@@ -980,7 +980,7 @@ def test_solver_sub_dependencies_with_not_supported_python_version_transitive(
)
-def test_solver_with_dependency_in_both_default_and_dev_dependencies(
+def test_solver_with_dependency_in_both_main_and_dev_dependencies(
solver: Solver, repo: Repository, package: Package
):
solver.provider.set_package_python_versions("^3.5")