diff --git a/lib/modules/versioning/pep440/index.spec.ts b/lib/modules/versioning/pep440/index.spec.ts index 84fe37c5090bd9..09db07eef1d56f 100644 --- a/lib/modules/versioning/pep440/index.spec.ts +++ b/lib/modules/versioning/pep440/index.spec.ts @@ -192,6 +192,123 @@ describe('modules/versioning/pep440/index', () => { } ); + test.each` + currentValue | rangeStrategy | currentVersion | newVersion | expected + ${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'1.0.0'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.0.3'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.0.3'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.0.3'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>=1.2.0'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>=1.2.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.2.0'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.2.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>=1.2.0'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.2.0'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.0.3'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.0.3'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.0.3'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.2.*'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.2.*'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.2.*'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.0.*'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.0.*'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'==1.0.*'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1.2.2.3'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1.2.2.3'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1.2.3'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1.2.3'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1.2.3'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1.2'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1.2'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1.2'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<1'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<2.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<2.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'<2.0.0'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>0.9.8'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>0.9.8'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>0.9.8'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>2.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>2.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>2.0.0'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>=2.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>=2.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>=2.0.0'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.1.0, !=1.1.1'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.1.0, !=1.1.1'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.1.0, !=1.1.1'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.1.0,!=1.1.1'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.1.0,!=1.1.1'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.1.0,!=1.1.1'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${' '} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${' '} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${' '} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'invalid'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'invalid'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'invalid'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'===1.0.3'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'===1.0.3'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'===1.0.3'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'!=1.2.3'} | ${'bump'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'!=1.2.3'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'!=1.2.3'} | ${'pin'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'~=1.1.0,!=1.1.1'} | ${'unsupported'} | ${'1.0.0'} | ${'1.2.3'} | ${'1.2.3'} + ${'>=19.12.2,<20.13.9'} | ${'replace'} | ${'19.12.2'} | ${'21.3.1'} | ${'21.3.1'} + ${'>=19.12.2,<19.13.9'} | ${'replace'} | ${'19.12.2'} | ${'20.3.1'} | ${'20.3.1'} + ${'>=19.12.2,<19.13.0'} | ${'replace'} | ${'19.12.2'} | ${'20.3.1'} | ${'20.3.1'} + ${'>=19.12.2,<19.13.0'} | ${'replace'} | ${'19.12.2'} | ${'20.3.0'} | ${'20.3.0'} + ${'>=19.12.2,<19.13.0'} | ${'replace'} | ${'19.12.2'} | ${'19.13.1'} | ${'19.13.1'} + ${'>=19.12.2,<19.13.0'} | ${'replace'} | ${'19.12.2'} | ${'19.13.0'} | ${'19.13.0'} + ${'>=19.12.2,<19.13.0'} | ${'auto'} | ${'19.12.2'} | ${'19.13.0'} | ${'19.13.0'} + ${'>=19.12.2,<20.13.9'} | ${'widen'} | ${'19.12.2'} | ${'21.3.1'} | ${'21.3.1'} + ${'>=19.12.2,<19.13.9'} | ${'widen'} | ${'19.12.2'} | ${'20.3.1'} | ${'20.3.1'} + ${'>=19.12.2,<19.13.0'} | ${'widen'} | ${'19.12.2'} | ${'20.3.1'} | ${'20.3.1'} + ${'>=19.12.2,<19.13.0'} | ${'widen'} | ${'19.12.2'} | ${'20.3.0'} | ${'20.3.0'} + ${'>=19.12.2,<19.13.0'} | ${'widen'} | ${'19.12.2'} | ${'19.13.1'} | ${'19.13.1'} + ${'>=19.12.2,<19.13.0'} | ${'widen'} | ${'19.12.2'} | ${'19.13.0'} | ${'19.13.0'} + ${'~=7.2'} | ${'replace'} | ${'7.2.0'} | ${'8.0.1'} | ${'8.0.1'} + ${'~=7.2'} | ${'replace'} | ${'7.2.0'} | ${'8'} | ${'8'} + ${'~=7.2.0'} | ${'replace'} | ${'7.2.0'} | ${'8.2'} | ${'8.2'} + ${'~=7.2'} | ${'widen'} | ${'7.2.0'} | ${'8.0.1'} | ${'8.0.1'} + ${'~=7.2'} | ${'widen'} | ${'7.2.0'} | ${'8'} | ${'8'} + ${'~=7.2.0'} | ${'widen'} | ${'7.2.0'} | ${'8.2'} | ${'8.2'} + ${'==3.2.*,>=3.2.2'} | ${'replace'} | ${'3.2.2'} | ${'4.1.1'} | ${'4.1.1'} + ${'==3.2.*,>=3.2.2'} | ${'replace'} | ${'3.2.2'} | ${'4.0.0'} | ${'4.0.0'} + ${'>=1.0.0,<1.1.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.0'} | ${'1.2.0'} + ${'<1.3.0'} | ${'bump'} | ${'1.3.0'} | ${'0.9.2'} | ${'0.9.2'} + ${'<1.3.0'} | ${'bump'} | ${'0.9.0'} | ${'0.9.2'} | ${'0.9.2'} + ${'<=1.3.0'} | ${'bump'} | ${'0.9.0'} | ${'0.9.2'} | ${'0.9.2'} + ${'<=1.3.0'} | ${'bump'} | ${'1.3.0'} | ${'0.9.2'} | ${'0.9.2'} + ${'<1.3.0'} | ${'bump'} | ${'1.3.0'} | ${'1.6.0'} | ${'1.6.0'} + ${'<1.3.0'} | ${'bump'} | ${'0.9.0'} | ${'1.6.0'} | ${'1.6.0'} + ${'<=1.3.0'} | ${'bump'} | ${'0.9.0'} | ${'1.6.0'} | ${'1.6.0'} + ${'<=1.3.0'} | ${'bump'} | ${'1.3.0'} | ${'1.6.0'} | ${'1.6.0'} + ${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'==1.2.3'} | ${'==1.2.3'} + ${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'>=1.2.3'} | ${'>=1.2.3'} + ${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'<=1.2.3'} | ${'<=1.2.3'} + ${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'~=1.2.3'} | ${'~=1.2.3'} + ${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'!=1.2.3'} | ${'!=1.2.3'} + ${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'>1.2.3'} | ${'>1.2.3'} + ${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'<1.2.3'} | ${'<1.2.3'} + `( + 'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"', + ({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => { + const isReplacement = true; + const res = pep440.getNewValue({ + currentValue, + rangeStrategy, + currentVersion, + newVersion, + isReplacement, + }); + expect(res).toEqual(expected); + } + ); + test.each` version | range | expected ${'0.9.9.9'} | ${'>= 1.0.0, < 2.0.0'} | ${true} diff --git a/lib/modules/versioning/pep440/range.ts b/lib/modules/versioning/pep440/range.ts index ab112037079b31..5e2dde8ef8bf16 100644 --- a/lib/modules/versioning/pep440/range.ts +++ b/lib/modules/versioning/pep440/range.ts @@ -94,15 +94,16 @@ export function getNewValue({ rangeStrategy, currentVersion, newVersion, + isReplacement, }: NewValueConfig): string | null { let ranges: Range[]; let updatedRange: (string | null)[]; - if (rangeStrategy === 'pin') { + if (rangeStrategy === 'pin' && !isReplacement) { return '==' + newVersion; } // no symbol: accept only that specific version specified - if (currentValue === currentVersion) { + if (currentValue === currentVersion || isReplacement) { return newVersion; } diff --git a/lib/modules/versioning/types.ts b/lib/modules/versioning/types.ts index 838431e809f005..608d08e71031e7 100644 --- a/lib/modules/versioning/types.ts +++ b/lib/modules/versioning/types.ts @@ -6,6 +6,7 @@ export interface NewValueConfig { rangeStrategy: RangeStrategy; currentVersion?: string; newVersion: string; + isReplacement?: boolean; } export interface VersioningApi { // validation diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts index 19b076d7dd7dc5..816381d7a42bca 100644 --- a/lib/workers/repository/process/lookup/index.ts +++ b/lib/workers/repository/process/lookup/index.ts @@ -163,6 +163,7 @@ export async function lookupUpdates( currentValue: currentValue!, newVersion: config.replacementVersion, rangeStrategy: rangeStrategy!, + isReplacement: true, })!, }); }