Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pep621): add support for dependency-groups (PEP 735) #32148

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pytest = [
"pytest-mock",
]

[dependency-groups]
typing = ["mypy==1.13.0", "types-requests"]
coverage = ["pytest-cov==5.0.0"]
all = [{include-group = "typing"}, {include-group = "coverage"}, "click==8.1.7"]

[tool.pdm.dev-dependencies]
test = [
"pdm[pytest]",
Expand Down
41 changes: 41 additions & 0 deletions lib/modules/manager/pep621/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,47 @@ describe('modules/manager/pep621/extract', () => {
},
]);

const dependenciesFromDependencyGroups = result?.deps.filter(
(dep) => dep.depType === 'dependency-groups',
);
expect(dependenciesFromDependencyGroups).toEqual([
{
packageName: 'mypy',
datasource: 'pypi',
depType: 'dependency-groups',
currentValue: '==1.13.0',
currentVersion: '1.13.0',
depName: 'mypy',
managerData: { depGroup: 'typing' },
},
{
packageName: 'types-requests',
datasource: 'pypi',
depType: 'dependency-groups',
skipReason: 'unspecified-version',
depName: 'types-requests',
managerData: { depGroup: 'typing' },
},
{
packageName: 'pytest-cov',
datasource: 'pypi',
depType: 'dependency-groups',
currentValue: '==5.0.0',
currentVersion: '5.0.0',
depName: 'pytest-cov',
managerData: { depGroup: 'coverage' },
},
{
packageName: 'click',
datasource: 'pypi',
depType: 'dependency-groups',
currentValue: '==8.1.7',
currentVersion: '8.1.7',
depName: 'click',
managerData: { depGroup: 'all' },
},
]);

const pdmDevDependencies = result?.deps.filter(
(dep) => dep.depType === 'tool.pdm.dev-dependencies',
);
Expand Down
6 changes: 6 additions & 0 deletions lib/modules/manager/pep621/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export async function extractPackageFile(
deps.push(
...parseDependencyList(depTypes.dependencies, def.project?.dependencies),
);
deps.push(
...parseDependencyGroupRecord(
depTypes.dependencyGroups,
def['dependency-groups'],
),
);
deps.push(
...parseDependencyGroupRecord(
depTypes.optionalDependencies,
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/pep621/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Available `depType`s:

- `project.dependencies`
- `project.optional-dependencies`
- `dependency-groups`
- `build-system.requires`
- `tool.pdm.dev-dependencies`
- `tool.uv.dev-dependencies`
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/manager/pep621/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export const PyProjectSchema = z.object({
'build-backend': z.string().optional(),
})
.optional(),
'dependency-groups': z
.record(
z.string(),
// Skip non-string entries, like `{include-group = "typing"}`, as they are not dependencies.
LooseArray(z.string()),
)
.optional(),
tool: z
.object({
pdm: PdmSchema.optional(),
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/pep621/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const pep508Regex = regEx(
export const depTypes = {
dependencies: 'project.dependencies',
optionalDependencies: 'project.optional-dependencies',
dependencyGroups: 'dependency-groups',
pdmDevDependencies: 'tool.pdm.dev-dependencies',
uvDevDependencies: 'tool.uv.dev-dependencies',
uvSources: 'tool.uv.sources',
Expand Down