Skip to content

Commit

Permalink
feat(pep621): add support for dependency-groups (PEP 735) (#32148)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <[email protected]>
  • Loading branch information
mkniewallner and secustor authored Oct 26, 2024
1 parent cc6696b commit babd6da
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
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

0 comments on commit babd6da

Please sign in to comment.