From 7692f5e85510b7210ef44b8f957d33537b032ad8 Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Fri, 25 Oct 2024 21:58:20 +0200 Subject: [PATCH 1/4] feat(pep621): add support for `dependency-groups` (PEP 735) --- .../__fixtures__/pyproject_with_pdm.toml | 5 +++ lib/modules/manager/pep621/extract.spec.ts | 41 +++++++++++++++++++ lib/modules/manager/pep621/extract.ts | 6 +++ lib/modules/manager/pep621/readme.md | 1 + lib/modules/manager/pep621/schema.ts | 10 +++++ lib/modules/manager/pep621/utils.ts | 1 + 6 files changed, 64 insertions(+) diff --git a/lib/modules/manager/pep621/__fixtures__/pyproject_with_pdm.toml b/lib/modules/manager/pep621/__fixtures__/pyproject_with_pdm.toml index 915cf6063ca561..95b5a8b44ecfd5 100644 --- a/lib/modules/manager/pep621/__fixtures__/pyproject_with_pdm.toml +++ b/lib/modules/manager/pep621/__fixtures__/pyproject_with_pdm.toml @@ -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]", diff --git a/lib/modules/manager/pep621/extract.spec.ts b/lib/modules/manager/pep621/extract.spec.ts index e9427b0ac81ac7..45cb094ee631ea 100644 --- a/lib/modules/manager/pep621/extract.spec.ts +++ b/lib/modules/manager/pep621/extract.spec.ts @@ -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', ); diff --git a/lib/modules/manager/pep621/extract.ts b/lib/modules/manager/pep621/extract.ts index 12a7c1803d4c37..e63b229701e410 100644 --- a/lib/modules/manager/pep621/extract.ts +++ b/lib/modules/manager/pep621/extract.ts @@ -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, diff --git a/lib/modules/manager/pep621/readme.md b/lib/modules/manager/pep621/readme.md index 003c08102e8755..db3ac79b0c7268 100644 --- a/lib/modules/manager/pep621/readme.md +++ b/lib/modules/manager/pep621/readme.md @@ -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` diff --git a/lib/modules/manager/pep621/schema.ts b/lib/modules/manager/pep621/schema.ts index a13f466b21e555..3eadfa254a16a9 100644 --- a/lib/modules/manager/pep621/schema.ts +++ b/lib/modules/manager/pep621/schema.ts @@ -1,3 +1,4 @@ +import is from '@sindresorhus/is'; import { z } from 'zod'; import { LooseArray, LooseRecord, Toml } from '../../../util/schema-utils'; @@ -83,6 +84,15 @@ export const PyProjectSchema = z.object({ 'build-backend': z.string().optional(), }) .optional(), + 'dependency-groups': z + .record( + z.string(), + z + .array(z.union([z.string(), z.object({})])) + // Skip non-string entries, like `{include-group = "typing"}`, as they are not dependencies. + .transform((deps) => deps.filter(is.string)), + ) + .optional(), tool: z .object({ pdm: PdmSchema.optional(), diff --git a/lib/modules/manager/pep621/utils.ts b/lib/modules/manager/pep621/utils.ts index 2e7aaa733d8c11..faf88e2006cc29 100644 --- a/lib/modules/manager/pep621/utils.ts +++ b/lib/modules/manager/pep621/utils.ts @@ -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', From d946720812bb5fbf6c72d3c2b41999cecf86bfbb Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Sat, 26 Oct 2024 12:39:40 +0200 Subject: [PATCH 2/4] refactor(pep621): use `LooseArray` Co-authored-by: Sebastian Poxhofer --- lib/modules/manager/pep621/schema.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/modules/manager/pep621/schema.ts b/lib/modules/manager/pep621/schema.ts index 3eadfa254a16a9..59f53a26c4e4d2 100644 --- a/lib/modules/manager/pep621/schema.ts +++ b/lib/modules/manager/pep621/schema.ts @@ -87,10 +87,8 @@ export const PyProjectSchema = z.object({ 'dependency-groups': z .record( z.string(), - z - .array(z.union([z.string(), z.object({})])) - // Skip non-string entries, like `{include-group = "typing"}`, as they are not dependencies. - .transform((deps) => deps.filter(is.string)), + // Skip non-string entries, like `{include-group = "typing"}`, as they are not dependencies. + LooseArray(z.string()) ) .optional(), tool: z From 38d93571593d70db0774bb257529264e0acd7c03 Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Sat, 26 Oct 2024 12:41:00 +0200 Subject: [PATCH 3/4] chore: run `pnpm prettier-fix` --- lib/modules/manager/pep621/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/pep621/schema.ts b/lib/modules/manager/pep621/schema.ts index 59f53a26c4e4d2..46253aa3d64e4f 100644 --- a/lib/modules/manager/pep621/schema.ts +++ b/lib/modules/manager/pep621/schema.ts @@ -88,7 +88,7 @@ export const PyProjectSchema = z.object({ .record( z.string(), // Skip non-string entries, like `{include-group = "typing"}`, as they are not dependencies. - LooseArray(z.string()) + LooseArray(z.string()), ) .optional(), tool: z From 935c0e50dcb3a745010543e8d3706fe43eac9324 Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Sat, 26 Oct 2024 12:45:25 +0200 Subject: [PATCH 4/4] refactor(pep621): remove unused import --- lib/modules/manager/pep621/schema.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/modules/manager/pep621/schema.ts b/lib/modules/manager/pep621/schema.ts index 46253aa3d64e4f..2d6f8a2f491d58 100644 --- a/lib/modules/manager/pep621/schema.ts +++ b/lib/modules/manager/pep621/schema.ts @@ -1,4 +1,3 @@ -import is from '@sindresorhus/is'; import { z } from 'zod'; import { LooseArray, LooseRecord, Toml } from '../../../util/schema-utils';