From 96c3399a86f098d67303a3e8c242926e8a9720c8 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Wed, 26 Feb 2025 13:34:05 +0100 Subject: [PATCH] fix(python): use pep440 versioning --- src/cli/tools/python/utils.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/cli/tools/python/utils.ts b/src/cli/tools/python/utils.ts index 239e75e3dd..6c03f83f54 100644 --- a/src/cli/tools/python/utils.ts +++ b/src/cli/tools/python/utils.ts @@ -1,12 +1,12 @@ import fs from 'node:fs/promises'; import path from 'node:path'; -import { valid as validPep440 } from '@renovatebot/pep440'; +import { major, minor, satisfies, valid } from '@renovatebot/pep440'; import { execa } from 'execa'; import { parse as parseIni } from 'ini'; import { inject, injectable } from 'inversify'; import { BaseInstallService } from '../../install-tool/base-install.service'; import { EnvService, PathService, VersionService } from '../../services'; -import { logger, parse, semverGte } from '../../utils'; +import { logger } from '../../utils'; @injectable() export abstract class PythonBaseInstallService extends BaseInstallService { @@ -171,7 +171,7 @@ export abstract class PipBaseInstallService extends PythonBaseInstallService { } override async validate(version: string): Promise { - if (!validPep440(version)) { + if (!valid(version)) { return false; } @@ -209,14 +209,13 @@ export abstract class PipBaseInstallService extends PythonBaseInstallService { case 'pip-tools': { // keyrings.envvars added support for looking up credentials by service name only, which is needed by the Renovate pip-compile manager // keyrings.envvars package does not support python versions lower than 3.9 - const pVer = parse(pythonVersion); - if (pVer.major > 3 || (pVer.major === 3 && pVer.minor >= 9)) { + if (satisfies(pythonVersion, '>=3.9')) { return ['keyrings.envvars>=1.1.0']; } break; } case 'poetry': { - if (semverGte(version, '1.2.1')) { + if (satisfies(version, '>=1.2.1')) { return ['poetry-plugin-pypi-mirror']; } } @@ -229,12 +228,11 @@ export abstract class PipBaseInstallService extends PythonBaseInstallService { pythonVersion: string, file = 'WHEEL', ): string { - const pVer = parse(pythonVersion); return path.join( this.pathSvc.versionedToolPath(this.name, version), pythonVersion, 'lib', - `python${pVer.major}.${pVer.minor}`, + `python${major(pythonVersion)}.${minor(pythonVersion)}`, 'site-packages', `${this.tool(version).replaceAll(/[-_.]+/g, '_')}-${version}.dist-info`, file,