Commit 6beef611 by Randy Döring Committed by Arun Babu Neelicattu

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)
parent dca0c562
...@@ -218,7 +218,7 @@ option is used. ...@@ -218,7 +218,7 @@ option is used.
* `--without`: The dependency groups to ignore. * `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include. * `--with`: The optional dependency groups to include.
* `--only`: The only 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. * `--sync`: Synchronize the environment with the locked packages and the specified groups.
* `--no-root`: Do not install the root package (your project). * `--no-root`: Do not install the root package (your project).
* `--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).
...@@ -258,7 +258,7 @@ update the constraint, for example `^2.3`. You can do this using the `add` comma ...@@ -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. * `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include. * `--with`: The optional dependency groups to include.
* `--only`: The only 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). * `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose).
* `--no-dev` : Do not update the development dependencies. (**Deprecated**) * `--no-dev` : Do not update the development dependencies. (**Deprecated**)
* `--lock` : Do not perform install (only update the lockfile). * `--lock` : Do not perform install (only update the lockfile).
...@@ -439,7 +439,7 @@ required by ...@@ -439,7 +439,7 @@ required by
* `--without`: The dependency groups to ignore. * `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include. * `--with`: The optional dependency groups to include.
* `--only`: The only 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**) * `--no-dev`: Do not list the dev dependencies. (**Deprecated**)
* `--tree`: List the dependencies as a tree. * `--tree`: List the dependencies as a tree.
* `--latest (-l)`: Show the latest version. * `--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 ...@@ -626,7 +626,7 @@ and is also available as a pre-commit hook. See [pre-commit hooks](/docs/pre-com
{{% /note %}} {{% /note %}}
{{% 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. group defined in `tool.poetry.dependencies` when used without specifying any options.
{{% /note %}} {{% /note %}}
...@@ -641,7 +641,7 @@ group defined in `tool.poetry.dependencies` when used without specifying any opt ...@@ -641,7 +641,7 @@ group defined in `tool.poetry.dependencies` when used without specifying any opt
* `--without`: The dependency groups to ignore. * `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include. * `--with`: The optional dependency groups to include.
* `--only`: The only 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-hashes`: Exclude hashes from the exported file.
* `--without-urls`: Exclude source repository urls from the exported file. * `--without-urls`: Exclude source repository urls from the exported file.
* `--with-credentials`: Include credentials for extra indices. * `--with-credentials`: Include credentials for extra indices.
......
...@@ -37,10 +37,10 @@ the dependencies logically. ...@@ -37,10 +37,10 @@ the dependencies logically.
{{% /note %}} {{% /note %}}
{{% 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 ```toml
[tool.poetry.dependencies] # Default dependency group [tool.poetry.dependencies] # main dependency group
httpx = "*" httpx = "*"
pendulum = "*" pendulum = "*"
...@@ -115,7 +115,7 @@ If the group does not already exist, it will be created automatically. ...@@ -115,7 +115,7 @@ If the group does not already exist, it will be created automatically.
`poetry install`. `poetry install`.
{{% note %}} {{% 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 `tool.poetry.dependencies` as well as all groups that are not explicitly marked as an
[optional group]({{< relref "#optional-groups" >}}). [optional group]({{< relref "#optional-groups" >}}).
{{% /note %}} {{% /note %}}
...@@ -151,10 +151,10 @@ poetry install --only docs ...@@ -151,10 +151,10 @@ poetry install --only docs
{{% note %}} {{% note %}}
If you only want to install the project's runtime dependencies, you can do so with the If you only want to install the project's runtime dependencies, you can do so with the
`--only default` notation: `--only main` notation:
```bash ```bash
poetry install --only default poetry install --only main
``` ```
{{% /note %}} {{% /note %}}
......
...@@ -7,6 +7,12 @@ from typing import cast ...@@ -7,6 +7,12 @@ from typing import cast
from cleo.helpers import argument from cleo.helpers import argument
from cleo.helpers import option 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.init import InitCommand
from poetry.console.commands.installer_command import InstallerCommand from poetry.console.commands.installer_command import InstallerCommand
...@@ -23,7 +29,7 @@ class AddCommand(InstallerCommand, InitCommand): ...@@ -23,7 +29,7 @@ class AddCommand(InstallerCommand, InitCommand):
"-G", "-G",
"The group to add the dependency to.", "The group to add the dependency to.",
flag=False, flag=False,
default="default", default=MAIN_GROUP,
), ),
option("dev", "D", "Add as a development dependency."), option("dev", "D", "Add as a development dependency."),
option("editable", "e", "Add vcs/path dependencies as editable."), option("editable", "e", "Add vcs/path dependencies as editable."),
...@@ -111,7 +117,7 @@ You can specify a package in the following forms: ...@@ -111,7 +117,7 @@ You can specify a package in the following forms:
content = self.poetry.file.read() content = self.poetry.file.read()
poetry_content = content["tool"]["poetry"] poetry_content = content["tool"]["poetry"]
if group == "default": if group == MAIN_GROUP:
if "dependencies" not in poetry_content: if "dependencies" not in poetry_content:
poetry_content["dependencies"] = table() poetry_content["dependencies"] = table()
......
...@@ -4,6 +4,12 @@ from typing import TYPE_CHECKING ...@@ -4,6 +4,12 @@ from typing import TYPE_CHECKING
from cleo.helpers import option 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 from poetry.console.commands.env_command import EnvCommand
...@@ -34,8 +40,7 @@ class GroupCommand(EnvCommand): ...@@ -34,8 +40,7 @@ class GroupCommand(EnvCommand):
option( option(
"default", "default",
None, None,
"Only include the default dependencies." "Only include the main dependencies. (<warning>Deprecated</warning>)",
" (<warning>Deprecated</warning>)",
), ),
option( option(
"only", "only",
...@@ -67,10 +72,10 @@ class GroupCommand(EnvCommand): ...@@ -67,10 +72,10 @@ class GroupCommand(EnvCommand):
} }
for opt, new, group in [ for opt, new, group in [
("default", "only", "default"), ("default", "only", MAIN_GROUP),
("no-dev", "only", "default"), ("no-dev", "only", MAIN_GROUP),
("dev", "with", "dev"), ("dev", "with", "dev"),
("dev-only", "without", "default"), ("dev-only", "without", MAIN_GROUP),
]: ]:
if self.io.input.has_option(opt) and self.option(opt): if self.io.input.has_option(opt) and self.option(opt):
self.line_error( self.line_error(
......
...@@ -5,6 +5,12 @@ from typing import Any ...@@ -5,6 +5,12 @@ from typing import Any
from cleo.helpers import argument from cleo.helpers import argument
from cleo.helpers import option 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 from poetry.console.commands.installer_command import InstallerCommand
...@@ -55,10 +61,10 @@ list of installed packages ...@@ -55,10 +61,10 @@ list of installed packages
] ]
for group_name, section in [ for group_name, section in [
("default", poetry_content["dependencies"]) (MAIN_GROUP, poetry_content["dependencies"])
] + group_sections: ] + group_sections:
removed += self._remove_packages(packages, section, group_name) removed += self._remove_packages(packages, section, group_name)
if group_name != "default": if group_name != MAIN_GROUP:
if not section: if not section:
del poetry_content["group"][group_name] del poetry_content["group"][group_name]
else: else:
......
...@@ -14,6 +14,12 @@ from typing import Iterator ...@@ -14,6 +14,12 @@ from typing import Iterator
from typing import Sequence from typing import Sequence
from poetry.core.packages.dependency import Dependency 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.packages.package import Package
from poetry.core.semver.helpers import parse_constraint from poetry.core.semver.helpers import parse_constraint
from poetry.core.semver.version import Version from poetry.core.semver.version import Version
...@@ -121,7 +127,7 @@ class Locker: ...@@ -121,7 +127,7 @@ class Locker:
) )
package.description = info.get("description", "") package.description = info.get("description", "")
package.category = info.get("category", "main") package.category = info.get("category", "main")
package.groups = info.get("groups", ["default"]) package.groups = info.get("groups", [MAIN_GROUP])
package.optional = info["optional"] package.optional = info["optional"]
if "hashes" in lock_data["metadata"]: if "hashes" in lock_data["metadata"]:
# Old lock so we create dummy files from the hashes # Old lock so we create dummy files from the hashes
......
...@@ -10,6 +10,12 @@ from typing import FrozenSet ...@@ -10,6 +10,12 @@ from typing import FrozenSet
from typing import Iterator from typing import Iterator
from typing import Tuple 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 import resolve_version
from poetry.mixology.failure import SolveFailure from poetry.mixology.failure import SolveFailure
from poetry.packages import DependencyPackage from poetry.packages import DependencyPackage
...@@ -270,7 +276,7 @@ class PackageNode(DFSNode): ...@@ -270,7 +276,7 @@ class PackageNode(DFSNode):
self.groups: frozenset[str] = frozenset() self.groups: frozenset[str] = frozenset()
self.optional = True self.optional = True
elif dep: 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.groups = dep.groups
self.optional = dep.is_optional() self.optional = dep.is_optional()
else: else:
...@@ -348,7 +354,7 @@ def aggregate_package_nodes(nodes: list[PackageNode]) -> tuple[Package, int]: ...@@ -348,7 +354,7 @@ def aggregate_package_nodes(nodes: list[PackageNode]) -> tuple[Package, int]:
for node in nodes: for node in nodes:
groups.extend(node.groups) 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) optional = all(node.optional for node in nodes)
for node in nodes: for node in nodes:
node.depth = depth node.depth = depth
......
...@@ -7,6 +7,11 @@ import pytest ...@@ -7,6 +7,11 @@ import pytest
from poetry.core.masonry.utils.module import ModuleOrPackageNotFound 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: if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester from cleo.testers.command_tester import CommandTester
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
...@@ -65,23 +70,23 @@ def tester( ...@@ -65,23 +70,23 @@ def tester(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("options", "groups"), ("options", "groups"),
[ [
("", {"default", "foo", "bar", "baz", "bim"}), ("", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
("--only default", {"default"}), (f"--only {MAIN_GROUP}", {MAIN_GROUP}),
("--only foo", {"foo"}), ("--only foo", {"foo"}),
("--only foo,bar", {"foo", "bar"}), ("--only foo,bar", {"foo", "bar"}),
("--only bam", {"bam"}), ("--only bam", {"bam"}),
("--with bam", {"default", "foo", "bar", "baz", "bim", "bam"}), ("--with bam", {MAIN_GROUP, "foo", "bar", "baz", "bim", "bam"}),
("--without foo,bar", {"default", "baz", "bim"}), ("--without foo,bar", {MAIN_GROUP, "baz", "bim"}),
("--without default", {"foo", "bar", "baz", "bim"}), (f"--without {MAIN_GROUP}", {"foo", "bar", "baz", "bim"}),
("--with foo,bar --without baz --without bim --only bam", {"bam"}), ("--with foo,bar --without baz --without bim --only bam", {"bam"}),
# net result zero options # net result zero options
("--with foo", {"default", "foo", "bar", "baz", "bim"}), ("--with foo", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
("--without bam", {"default", "foo", "bar", "baz", "bim"}), ("--without bam", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
("--with bam --without bam", {"default", "foo", "bar", "baz", "bim"}), ("--with bam --without bam", {MAIN_GROUP, "foo", "bar", "baz", "bim"}),
("--with foo --without foo", {"default", "bar", "baz", "bim"}), ("--with foo --without foo", {MAIN_GROUP, "bar", "baz", "bim"}),
# deprecated options # deprecated options
("--default", {"default"}), ("--default", {MAIN_GROUP}),
("--no-dev", {"default"}), ("--no-dev", {MAIN_GROUP}),
("--dev-only", {"foo", "bar", "baz", "bim"}), ("--dev-only", {"foo", "bar", "baz", "bim"}),
], ],
) )
......
...@@ -6,6 +6,12 @@ import pytest ...@@ -6,6 +6,12 @@ import pytest
from poetry.core.packages.dependency_group import DependencyGroup 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 poetry.factory import Factory
from tests.helpers import get_package from tests.helpers import get_package
...@@ -197,13 +203,13 @@ cachy 0.1.0 Cachy package ...@@ -197,13 +203,13 @@ cachy 0.1.0 Cachy package
""", """,
), ),
( (
"--without default", f"--without {MAIN_GROUP}",
"""\ """\
pytest 3.7.3 Pytest package pytest 3.7.3 Pytest package
""", """,
), ),
( (
"--only default", f"--only {MAIN_GROUP}",
"""\ """\
cachy 0.1.0 Cachy package cachy 0.1.0 Cachy package
""", """,
...@@ -228,7 +234,7 @@ pendulum 2.0.0 Pendulum package ...@@ -228,7 +234,7 @@ pendulum 2.0.0 Pendulum package
""", """,
), ),
( (
"--with time --without default,test", f"--with time --without {MAIN_GROUP},test",
"""\ """\
pendulum 2.0.0 Pendulum package pendulum 2.0.0 Pendulum package
""", """,
......
...@@ -20,6 +20,12 @@ from poetry.core.packages.package import Package ...@@ -20,6 +20,12 @@ from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage from poetry.core.packages.project_package import ProjectPackage
from poetry.core.toml.file import TOMLFile 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.factory import Factory
from poetry.installation import Installer as BaseInstaller from poetry.installation import Installer as BaseInstaller
from poetry.installation.executor import Executor as BaseExecutor from poetry.installation.executor import Executor as BaseExecutor
...@@ -383,10 +389,10 @@ def _configure_run_install_dev( ...@@ -383,10 +389,10 @@ def _configure_run_install_dev(
([], 0, 0, 3, True), ([], 0, 0, 3, True),
(["dev"], 1, 0, 0, False), (["dev"], 1, 0, 0, False),
(["dev"], 0, 0, 2, True), (["dev"], 0, 0, 2, True),
(["default"], 2, 0, 0, False), ([MAIN_GROUP], 2, 0, 0, False),
(["default"], 0, 0, 1, True), ([MAIN_GROUP], 0, 0, 1, True),
(["default", "dev"], 3, 0, 0, False), ([MAIN_GROUP, "dev"], 3, 0, 0, False),
(["default", "dev"], 0, 0, 0, True), ([MAIN_GROUP, "dev"], 0, 0, 0, True),
], ],
) )
def test_run_install_with_dependency_groups( def test_run_install_with_dependency_groups(
......
...@@ -980,7 +980,7 @@ def test_solver_sub_dependencies_with_not_supported_python_version_transitive( ...@@ -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: Solver, repo: Repository, package: Package
): ):
solver.provider.set_package_python_versions("^3.5") solver.provider.set_package_python_versions("^3.5")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment