diff --git a/lib/modules/manager/poetry/__fixtures__/pyproject.1.toml b/lib/modules/manager/poetry/__fixtures__/pyproject.1.toml index ffd05ad66c44af..91c1198aaee1bf 100644 --- a/lib/modules/manager/poetry/__fixtures__/pyproject.1.toml +++ b/lib/modules/manager/poetry/__fixtures__/pyproject.1.toml @@ -11,11 +11,6 @@ dep2 = "^0.6.0" dep3 = "^0.33.6" python = "~2.7 || ^3.4" -[tool.poetry.extras] -extra_dep1 = "^0.8.3" -extra_dep2 = "^0.9.4" -extra_dep3 = "^0.4.0" - [tool.poetry.dev-dependencies] dev_dep1 = "^3.0" dev_dep2 = "Invalid version." diff --git a/lib/modules/manager/poetry/__fixtures__/pyproject.2.toml b/lib/modules/manager/poetry/__fixtures__/pyproject.2.toml index d48aebadf8db08..68aac43ee9480b 100644 --- a/lib/modules/manager/poetry/__fixtures__/pyproject.2.toml +++ b/lib/modules/manager/poetry/__fixtures__/pyproject.2.toml @@ -10,11 +10,21 @@ dep2 = { version = "^0.6.0" } dep3 = { path = "/some/path/", version = '^0.33.6' } dep4 = { path = "/some/path/" } dep5 = {} +extra_dep1 = {version = "^0.8.3", optional = true} +extra_dep2 = {version = "^0.9.4", optional = true} +extra_dep3 = {version = "^0.4.0", optional = true} [tool.poetry.extras] -extra_dep1 = "^0.8.3" -extra_dep2 = "^0.9.4" -extra_dep3 = '^0.4.0' +extra1 = ["extra_dep1", "extra_dep2"] +extra2 = ["extra_dep3"] + +[tool.poetry.dev-dependencies] +required_dev_dep = {version = "^3.0", optional = false} +optional_dev_dep = {version = "^3.0", optional = true} # NOTE: `optional = true` is meaningless here + +[tool.poetry.group.group1.dependencies] +required_group_dep = {version = "^3.0", optional = false} +optional_group_dep = {version = "^3.0", optional = true} # NOTE: `optional = true` is meaningless here [build-system] requires = ["poetry>=1.0", "wheel"] diff --git a/lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap b/lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap index ba728b78c5430d..98429c3744f9d4 100644 --- a/lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap +++ b/lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap @@ -397,7 +397,7 @@ exports[`modules/manager/poetry/extract extractPackageFile() extracts multiple d "depName": "extra_dep1", "depType": "extras", "managerData": { - "nestedVersion": false, + "nestedVersion": true, }, "packageName": "extra-dep1", "versioning": "poetry", @@ -408,7 +408,7 @@ exports[`modules/manager/poetry/extract extractPackageFile() extracts multiple d "depName": "extra_dep2", "depType": "extras", "managerData": { - "nestedVersion": false, + "nestedVersion": true, }, "packageName": "extra-dep2", "versioning": "poetry", @@ -419,11 +419,55 @@ exports[`modules/manager/poetry/extract extractPackageFile() extracts multiple d "depName": "extra_dep3", "depType": "extras", "managerData": { - "nestedVersion": false, + "nestedVersion": true, }, "packageName": "extra-dep3", "versioning": "poetry", }, + { + "currentValue": "^3.0", + "datasource": "pypi", + "depName": "required_dev_dep", + "depType": "dev-dependencies", + "managerData": { + "nestedVersion": true, + }, + "packageName": "required-dev-dep", + "versioning": "poetry", + }, + { + "currentValue": "^3.0", + "datasource": "pypi", + "depName": "optional_dev_dep", + "depType": "dev-dependencies", + "managerData": { + "nestedVersion": true, + }, + "packageName": "optional-dev-dep", + "versioning": "poetry", + }, + { + "currentValue": "^3.0", + "datasource": "pypi", + "depName": "required_group_dep", + "depType": "group1", + "managerData": { + "nestedVersion": true, + }, + "packageName": "required-group-dep", + "versioning": "poetry", + }, + { + "currentValue": "^3.0", + "datasource": "pypi", + "depName": "optional_group_dep", + "depType": "group1", + "managerData": { + "nestedVersion": true, + }, + "packageName": "optional-group-dep", + "versioning": "poetry", + }, ], "extractedConstraints": {}, "packageFileVersion": "0.1.0", @@ -508,39 +552,6 @@ exports[`modules/manager/poetry/extract extractPackageFile() extracts multiple d "packageName": "dev-dep2", "skipReason": "invalid-version", }, - { - "currentValue": "^0.8.3", - "datasource": "pypi", - "depName": "extra_dep1", - "depType": "extras", - "managerData": { - "nestedVersion": false, - }, - "packageName": "extra-dep1", - "versioning": "poetry", - }, - { - "currentValue": "^0.9.4", - "datasource": "pypi", - "depName": "extra_dep2", - "depType": "extras", - "managerData": { - "nestedVersion": false, - }, - "packageName": "extra-dep2", - "versioning": "poetry", - }, - { - "currentValue": "^0.4.0", - "datasource": "pypi", - "depName": "extra_dep3", - "depType": "extras", - "managerData": { - "nestedVersion": false, - }, - "packageName": "extra-dep3", - "versioning": "poetry", - }, ] `; diff --git a/lib/modules/manager/poetry/extract.spec.ts b/lib/modules/manager/poetry/extract.spec.ts index d9c3c82c1bee4c..5801cd73c93e6b 100644 --- a/lib/modules/manager/poetry/extract.spec.ts +++ b/lib/modules/manager/poetry/extract.spec.ts @@ -51,7 +51,7 @@ describe('modules/manager/poetry/extract', () => { it('extracts multiple dependencies', async () => { const res = await extractPackageFile(pyproject1toml, filename); expect(res?.deps).toMatchSnapshot(); - expect(res?.deps).toHaveLength(10); + expect(res?.deps).toHaveLength(7); expect(res?.extractedConstraints).toEqual({ python: '~2.7 || ^3.4', }); @@ -60,7 +60,7 @@ describe('modules/manager/poetry/extract', () => { it('extracts multiple dependencies (with dep = {version = "1.2.3"} case)', async () => { const res = await extractPackageFile(pyproject2toml, filename); expect(res).toMatchSnapshot(); - expect(res?.deps).toHaveLength(8); + expect(res?.deps).toHaveLength(12); }); it('handles case with no dependencies', async () => { diff --git a/lib/modules/manager/poetry/schema.ts b/lib/modules/manager/poetry/schema.ts index 25735dc3ff8654..6e650c21b2d0fc 100644 --- a/lib/modules/manager/poetry/schema.ts +++ b/lib/modules/manager/poetry/schema.ts @@ -21,6 +21,15 @@ import * as poetryVersioning from '../../versioning/poetry'; import { dependencyPattern } from '../pip_requirements/extract'; import type { PackageDependency, PackageFileContent } from '../types'; +const PoetryOptionalDependencyMixin = z + .object({ + optional: z.boolean().optional().catch(false), + }) + .transform( + ({ optional }): PackageDependency => + optional ? { depType: 'extras' } : {}, + ); + const PoetryPathDependency = z .object({ path: z.string(), @@ -37,7 +46,8 @@ const PoetryPathDependency = z } return dep; - }); + }) + .and(PoetryOptionalDependencyMixin); const PoetryGitDependency = z .object({ @@ -88,7 +98,8 @@ const PoetryGitDependency = z packageName: git, skipReason: 'git-dependency', }; - }); + }) + .and(PoetryOptionalDependencyMixin); const PoetryPypiDependency = z.union([ z @@ -106,7 +117,8 @@ const PoetryPypiDependency = z.union([ }, currentValue, }; - }), + }) + .and(PoetryOptionalDependencyMixin), z.string().transform( (version): PackageDependency => ({ datasource: PypiDatasource.id, @@ -259,12 +271,15 @@ export const PoetrySources = LooseArray(PoetrySource, { export const PoetrySectionSchema = z .object({ version: z.string().optional().catch(undefined), - dependencies: withDepType(PoetryDependencies, 'dependencies').optional(), + dependencies: withDepType( + PoetryDependencies, + 'dependencies', + false, + ).optional(), 'dev-dependencies': withDepType( PoetryDependencies, 'dev-dependencies', ).optional(), - extras: withDepType(PoetryDependencies, 'extras').optional(), group: PoetryGroupDependencies.optional(), source: PoetrySources, }) @@ -273,14 +288,12 @@ export const PoetrySectionSchema = z version, dependencies = [], 'dev-dependencies': devDependencies = [], - extras: extraDependencies = [], group: groupDependencies = [], source: sourceUrls, }) => { const deps: PackageDependency[] = [ ...dependencies, ...devDependencies, - ...extraDependencies, ...groupDependencies, ]; diff --git a/lib/util/schema-utils.ts b/lib/util/schema-utils.ts index f5a12c54095685..de637250c8f9cf 100644 --- a/lib/util/schema-utils.ts +++ b/lib/util/schema-utils.ts @@ -268,10 +268,12 @@ export const Toml = z.string().transform((str, ctx) => { export function withDepType< Output extends PackageDependency[], Schema extends ZodType, ->(schema: Schema, depType: string): ZodEffects { +>(schema: Schema, depType: string, force: boolean = true): ZodEffects { return schema.transform((deps) => { for (const dep of deps) { - dep.depType = depType; + if (!dep.depType || force) { + dep.depType = depType; + } } return deps; });