diff --git a/lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap b/lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap index 980e6cde67e796f277b2f4bea3072c90f984342c..03001cf902c407ced2173c6d0463ee4e98cd07a3 100644 --- a/lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap +++ b/lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap @@ -2,7 +2,6 @@ exports[`modules/manager/poetry/extract extractPackageFile() extracts mixed versioning types 1`] = ` Object { - "constraints": Object {}, "deps": Array [ Object { "currentValue": "0.2", @@ -345,13 +344,13 @@ Object { "versioning": "pep440", }, ], + "extractedConstraints": Object {}, "registryUrls": undefined, } `; exports[`modules/manager/poetry/extract extractPackageFile() extracts multiple dependencies (with dep = {version = "1.2.3"} case) 1`] = ` Object { - "constraints": Object {}, "deps": Array [ Object { "currentValue": "*", @@ -424,6 +423,7 @@ Object { "versioning": "poetry", }, ], + "extractedConstraints": Object {}, "registryUrls": undefined, } `; @@ -533,7 +533,6 @@ Array [ exports[`modules/manager/poetry/extract extractPackageFile() handles multiple constraint dependencies 1`] = ` Object { - "constraints": Object {}, "deps": Array [ Object { "currentValue": "", @@ -546,15 +545,13 @@ Object { "skipReason": "multiple-constraint-dep", }, ], + "extractedConstraints": Object {}, "registryUrls": undefined, } `; exports[`modules/manager/poetry/extract extractPackageFile() resolves lockedVersions from the lockfile 1`] = ` Object { - "constraints": Object { - "python": "^3.9", - }, "deps": Array [ Object { "currentValue": "*", @@ -568,6 +565,9 @@ Object { "versioning": "poetry", }, ], + "extractedConstraints": Object { + "python": "^3.9", + }, "registryUrls": undefined, } `; diff --git a/lib/modules/manager/poetry/extract.spec.ts b/lib/modules/manager/poetry/extract.spec.ts index a3c2af1540be655eb160e2e6fdbb52f3ee31fc44..1a390223fdd2f7e641bc4e418641b561ef0e3a87 100644 --- a/lib/modules/manager/poetry/extract.spec.ts +++ b/lib/modules/manager/poetry/extract.spec.ts @@ -44,7 +44,7 @@ describe('modules/manager/poetry/extract', () => { const res = await extractPackageFile(pyproject1toml, filename); expect(res.deps).toMatchSnapshot(); expect(res.deps).toHaveLength(9); - expect(res.constraints).toEqual({ + expect(res.extractedConstraints).toEqual({ python: '~2.7 || ^3.4', }); }); @@ -135,7 +135,7 @@ describe('modules/manager/poetry/extract', () => { fs.readLocalFile.mockResolvedValue(pyproject11tomlLock); const res = await extractPackageFile(pyproject11toml, filename); expect(res).toMatchSnapshot({ - constraints: { python: '^3.9' }, + extractedConstraints: { python: '^3.9' }, deps: [{ lockedVersion: '1.17.5' }], }); }); diff --git a/lib/modules/manager/poetry/extract.ts b/lib/modules/manager/poetry/extract.ts index 73ab25b3d28846b5b4242decf2e0a1bf174a50a8..66c4aae4d8d5e57560b8782a333c84f6b6bbdb78 100644 --- a/lib/modules/manager/poetry/extract.ts +++ b/lib/modules/manager/poetry/extract.ts @@ -128,16 +128,17 @@ export async function extractPackageFile( return null; } - const constraints: Record<string, any> = {}; + const extractedConstraints: Record<string, any> = {}; if (is.nonEmptyString(pyprojectfile.tool?.poetry?.dependencies?.python)) { - constraints.python = pyprojectfile.tool?.poetry?.dependencies?.python; + extractedConstraints.python = + pyprojectfile.tool?.poetry?.dependencies?.python; } const res: PackageFile = { deps, registryUrls: extractRegistries(pyprojectfile), - constraints, + extractedConstraints, }; // Try poetry.lock first let lockFile = getSiblingFileName(fileName, 'poetry.lock'); diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index cd92661139edc174ca36ae3b86bbfe7cd877c46c..16204ecc6308db8c53d8815deaef428646159beb 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -76,6 +76,7 @@ export interface PackageFile<T = Record<string, any>> autoReplaceStringTemplate?: string; hasYarnWorkspaces?: boolean; constraints?: Record<string, string>; + extractedConstraints?: Record<string, string>; datasource?: string; registryUrls?: string[]; additionalRegistryUrls?: string[]; diff --git a/lib/workers/repository/process/lookup/common.spec.ts b/lib/workers/repository/process/lookup/common.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..d859fc6239627db9d1c6b2912e2b296e653935d7 --- /dev/null +++ b/lib/workers/repository/process/lookup/common.spec.ts @@ -0,0 +1,57 @@ +import { mergeConfigConstraints } from './common'; +import type { LookupUpdateConfig } from './types'; + +describe('workers/repository/process/lookup/common', () => { + it('overrides extracted config with user config', () => { + const config: LookupUpdateConfig = { + datasource: '', + depName: '', + versioning: '', + rangeStrategy: 'pin', + }; + config.constraints = { + constraint1: 'configValue1', + constraint2: 'configValue2', + constraint3: 'configValue3', + }; + config.extractedConstraints = { + constraint3: 'extractedValue3', + constraint4: 'exractedValue4', + }; + expect(mergeConfigConstraints(config)).toMatchObject({ + datasource: '', + depName: '', + versioning: '', + rangeStrategy: 'pin', + constraints: { + constraint1: 'configValue1', + constraint2: 'configValue2', + constraint3: 'configValue3', + constraint4: 'exractedValue4', + }, + }); + }); + + it('sets config with extracted config', () => { + const config: LookupUpdateConfig = { + datasource: '', + depName: '', + versioning: '', + rangeStrategy: 'pin', + }; + config.extractedConstraints = { + constraint3: 'extractedValue3', + constraint4: 'exractedValue4', + }; + expect(mergeConfigConstraints(config)).toMatchObject({ + datasource: '', + depName: '', + versioning: '', + rangeStrategy: 'pin', + constraints: { + constraint3: 'extractedValue3', + constraint4: 'exractedValue4', + }, + }); + }); +}); diff --git a/lib/workers/repository/process/lookup/common.ts b/lib/workers/repository/process/lookup/common.ts new file mode 100644 index 0000000000000000000000000000000000000000..521bd99496bc44da4d3c952555f03e703ac24e91 --- /dev/null +++ b/lib/workers/repository/process/lookup/common.ts @@ -0,0 +1,14 @@ +import type { LookupUpdateConfig } from './types'; + +export function mergeConfigConstraints( + config: LookupUpdateConfig +): LookupUpdateConfig { + if (config?.extractedConstraints) { + config.constraints = { + ...config.extractedConstraints, + ...config.constraints, + }; + delete config.extractedConstraints; + } + return config; +} diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts index 33a1fbeefb40ebec8af4c529fbe9bf666feff7f8..9b682b4d03e2ae653fe889789c9113f4670f6ca2 100644 --- a/lib/workers/repository/process/lookup/index.ts +++ b/lib/workers/repository/process/lookup/index.ts @@ -19,6 +19,7 @@ import { clone } from '../../../../util/clone'; import { applyPackageRules } from '../../../../util/package-rules'; import { regEx } from '../../../../util/regex'; import { getBucket } from './bucket'; +import { mergeConfigConstraints } from './common'; import { getCurrentVersion } from './current'; import { filterVersions } from './filter'; import { filterInternalChecks } from './filter-checks'; @@ -74,6 +75,8 @@ export async function lookupUpdates( return res; } + config = mergeConfigConstraints(config); + const dependency = clone(await getPkgReleases(config)); if (!dependency) { // If dependency lookup fails then warn and return diff --git a/lib/workers/repository/process/lookup/types.ts b/lib/workers/repository/process/lookup/types.ts index 4c10d150a5e420c3d5aa643984a3ea2902369092..a985cd601a55370c37008acad39c508d744ead62 100644 --- a/lib/workers/repository/process/lookup/types.ts +++ b/lib/workers/repository/process/lookup/types.ts @@ -44,6 +44,7 @@ export interface LookupUpdateConfig datasource: string; depName: string; minimumConfidence?: string; + extractedConstraints?: Record<string, string>; } export interface UpdateResult {