Skip to content

Commit

Permalink
feat: Add support for dependency groups which include other groups only
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Feb 10, 2025
1 parent c0adab7 commit 445a089
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _configure_package_dependencies(
cls._add_package_group_dependencies(
package=package,
group=group,
dependencies=group_config["dependencies"],
dependencies=group_config.get("dependencies", {}),
)

for group_name, group_config in tool_poetry["group"].items():
Expand Down
13 changes: 11 additions & 2 deletions src/poetry/core/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,17 @@
"^[a-zA-Z-_.0-9]+$": {
"type": "object",
"description": "This represents a single dependency group",
"required": [
"dependencies"
"anyOf": [
{
"required": [
"dependencies"
]
},
{
"required": [
"include-groups"
]
}
],
"properties": {
"optional": {
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/project_with_included_groups_only/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
37 changes: 37 additions & 0 deletions tests/fixtures/project_with_included_groups_only/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[tool.poetry]
name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <[email protected]>"
]
license = "MIT"

readme = "README.rst"

homepage = "https://python-poetry.org"
repository = "https://github.com/python-poetry/poetry"
documentation = "https://python-poetry.org/docs"

keywords = ["packaging", "dependency", "poetry"]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"

[tool.poetry.group.lint.dependencies]
black = "*"

[tool.poetry.group.testing.dependencies]
pytest = "*"

[tool.poetry.group.all]
include-groups = [
"lint",
"testing",
]
Empty file.
13 changes: 13 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,3 +1094,16 @@ def test_create_poetry_with_unknown_nested_dependency_groups() -> None:
ValueError, match="Group 'dev' includes group 'testing' which is not defined"
):
_ = Factory().create_poetry(fixtures_dir / "project_with_unknown_nested_group")


def test_create_poetry_with_included_groups_only() -> None:
poetry = Factory().create_poetry(fixtures_dir / "project_with_included_groups_only")
assert len(poetry.package.all_requires) == 4
assert [
(dep.name, ",".join(dep.groups)) for dep in poetry.package.all_requires
] == [
("black", "lint"),
("pytest", "testing"),
("black", "all"),
("pytest", "all"),
]

0 comments on commit 445a089

Please sign in to comment.