Skip to content

Commit a28deaf

Browse files
committed
fix: also validate existing dependency groups
Signed-off-by: Henry Schreiner <[email protected]>
1 parent c7007c9 commit a28deaf

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/validate_pyproject/extra_validations.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class RedefiningStaticFieldAsDynamic(ValidationError):
2424
)
2525

2626

27+
class IncludedDependencyGroupMustExist(ValidationError):
28+
_DESC = """An included dependency group must exist and must not be cyclic.
29+
"""
30+
__doc__ = _DESC
31+
_URL = "https://peps.python.org/pep-0735/"
32+
33+
2734
def validate_project_dynamic(pyproject: T) -> T:
2835
project_table = pyproject.get("project", {})
2936
dynamic = project_table.get("dynamic", [])
@@ -49,4 +56,28 @@ def validate_project_dynamic(pyproject: T) -> T:
4956
return pyproject
5057

5158

52-
EXTRA_VALIDATIONS = (validate_project_dynamic,)
59+
def validate_include_depenency(pyproject: T) -> T:
60+
dependency_groups = pyproject.get("dependency-groups", {})
61+
for key, value in dependency_groups.items():
62+
for each in value:
63+
if (
64+
isinstance(each, dict)
65+
and (include_group := each.get("include-group"))
66+
and include_group not in dependency_groups
67+
):
68+
raise IncludedDependencyGroupMustExist(
69+
message=f"The included dependency group {include_group} doesn't exist",
70+
value={
71+
"field": include_group,
72+
},
73+
name=f"data.dependency_groups.{key}",
74+
definition={
75+
"description": cleandoc(IncludedDependencyGroupMustExist._DESC),
76+
"see": IncludedDependencyGroupMustExist._URL,
77+
},
78+
rule="PEP 621",
79+
)
80+
return pyproject
81+
82+
83+
EXTRA_VALIDATIONS = (validate_project_dynamic, validate_include_depenency)

0 commit comments

Comments
 (0)