Skip to content

Commit 445a089

Browse files
committed
feat: Add support for dependency groups which include other groups only
1 parent c0adab7 commit 445a089

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

src/poetry/core/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def _configure_package_dependencies(
347347
cls._add_package_group_dependencies(
348348
package=package,
349349
group=group,
350-
dependencies=group_config["dependencies"],
350+
dependencies=group_config.get("dependencies", {}),
351351
)
352352

353353
for group_name, group_config in tool_poetry["group"].items():

src/poetry/core/json/schemas/poetry-schema.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,17 @@
171171
"^[a-zA-Z-_.0-9]+$": {
172172
"type": "object",
173173
"description": "This represents a single dependency group",
174-
"required": [
175-
"dependencies"
174+
"anyOf": [
175+
{
176+
"required": [
177+
"dependencies"
178+
]
179+
},
180+
{
181+
"required": [
182+
"include-groups"
183+
]
184+
}
176185
],
177186
"properties": {
178187
"optional": {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
My Package
2+
==========
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[tool.poetry]
2+
name = "simple-project"
3+
version = "1.2.3"
4+
description = "Some description."
5+
authors = [
6+
"Sébastien Eustace <sebastien@eustace.io>"
7+
]
8+
license = "MIT"
9+
10+
readme = "README.rst"
11+
12+
homepage = "https://python-poetry.org"
13+
repository = "https://github.com/python-poetry/poetry"
14+
documentation = "https://python-poetry.org/docs"
15+
16+
keywords = ["packaging", "dependency", "poetry"]
17+
18+
classifiers = [
19+
"Topic :: Software Development :: Build Tools",
20+
"Topic :: Software Development :: Libraries :: Python Modules"
21+
]
22+
23+
# Requirements
24+
[tool.poetry.dependencies]
25+
python = "~2.7 || ^3.4"
26+
27+
[tool.poetry.group.lint.dependencies]
28+
black = "*"
29+
30+
[tool.poetry.group.testing.dependencies]
31+
pytest = "*"
32+
33+
[tool.poetry.group.all]
34+
include-groups = [
35+
"lint",
36+
"testing",
37+
]

tests/fixtures/project_with_included_groups_only/simple_project/__init__.py

Whitespace-only changes.

tests/test_factory.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,3 +1094,16 @@ def test_create_poetry_with_unknown_nested_dependency_groups() -> None:
10941094
ValueError, match="Group 'dev' includes group 'testing' which is not defined"
10951095
):
10961096
_ = Factory().create_poetry(fixtures_dir / "project_with_unknown_nested_group")
1097+
1098+
1099+
def test_create_poetry_with_included_groups_only() -> None:
1100+
poetry = Factory().create_poetry(fixtures_dir / "project_with_included_groups_only")
1101+
assert len(poetry.package.all_requires) == 4
1102+
assert [
1103+
(dep.name, ",".join(dep.groups)) for dep in poetry.package.all_requires
1104+
] == [
1105+
("black", "lint"),
1106+
("pytest", "testing"),
1107+
("black", "all"),
1108+
("pytest", "all"),
1109+
]

0 commit comments

Comments
 (0)