diff --git a/lib/modules/versioning/poetry/index.spec.ts b/lib/modules/versioning/poetry/index.spec.ts index 5a7285cac93bbfd45a579ff963d86bdd14556fd9..549bcd7dd805ca013c4e0ba640197f850911e29d 100644 --- a/lib/modules/versioning/poetry/index.spec.ts +++ b/lib/modules/versioning/poetry/index.spec.ts @@ -83,6 +83,8 @@ describe('modules/versioning/poetry/index', () => { it.each` version | expected + ${null} | ${false} + ${undefined} | ${false} ${'17.04.00'} | ${true} ${'17.b4.0'} | ${false} ${'1.2.3'} | ${true} @@ -101,6 +103,7 @@ describe('modules/versioning/poetry/index', () => { ${'renovatebot/renovate'} | ${false} ${'renovatebot/renovate#master'} | ${false} ${'https://github.com/renovatebot/renovate.git'} | ${false} + ${'>=2.6, !=3.0.*, !=3.1.*, !=3.2.*, <4'} | ${false} `('isValid("$version") === $expected', ({ version, expected }) => { expect(!!versioning.isValid(version)).toBe(expected); }); diff --git a/lib/modules/versioning/poetry/index.ts b/lib/modules/versioning/poetry/index.ts index 39066b703cacb37820783609f4ea74e585ac67fd..beb964c4a2f20006ef48d2c7b44247cf51b5c551 100644 --- a/lib/modules/versioning/poetry/index.ts +++ b/lib/modules/versioning/poetry/index.ts @@ -64,7 +64,19 @@ function isLessThanRange(version: string, range: string): boolean { } export function isValid(input: string): boolean { - return npm.isValid(poetry2npm(input)); + if (!input) { + return false; + } + + try { + return npm.isValid(poetry2npm(input, true)); + } catch (err) { + logger.once.debug( + { version: input }, + 'Poetry version or range is not supported by current implementation', + ); + return false; + } } function isStable(version: string): boolean { diff --git a/lib/modules/versioning/poetry/transform.ts b/lib/modules/versioning/poetry/transform.ts index 44f5c4da678285ac4b97449a01135ed80780577d..d5490768493870985f97c39c01def73f09f2a268 100644 --- a/lib/modules/versioning/poetry/transform.ts +++ b/lib/modules/versioning/poetry/transform.ts @@ -1,4 +1,5 @@ import semver from 'semver'; +import { regEx } from '../../../util/regex'; import { RANGE_COMPARATOR_PATTERN, VERSION_PATTERN } from './patterns'; interface LetterTag { @@ -100,7 +101,7 @@ export function semver2poetry(version?: string): string | null { * add a '^', because poetry treats versions without operators as * exact versions. */ -export function poetry2npm(input: string): string { +export function poetry2npm(input: string, throwOnUnsupported = false): string { // replace commas with spaces, then split at valid semver comparators const chunks = input .split(',') @@ -113,6 +114,14 @@ export function poetry2npm(input: string): string { .map((chunk) => poetry2semver(chunk, false) ?? chunk) .join('') .replace(/===/, '='); + if (throwOnUnsupported) { + const isUnsupported = transformed + .split(regEx(/\s+/)) + .some((part) => part.startsWith('!=')); // Patterns like `!=1.2.3` can't be easily translated between poetry/npm + if (isUnsupported) { + throw new Error('Unsupported by Poetry versioning implementation'); + } + } return transformed; }