Skip to content

Commit

Permalink
fix(python): use pep440 versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Feb 26, 2025
1 parent a6d5f38 commit 96c3399
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/cli/tools/python/utils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -171,7 +171,7 @@ export abstract class PipBaseInstallService extends PythonBaseInstallService {
}

override async validate(version: string): Promise<boolean> {
if (!validPep440(version)) {
if (!valid(version)) {
return false;
}

Expand Down Expand Up @@ -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'];
}
}
Expand All @@ -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,
Expand Down

0 comments on commit 96c3399

Please sign in to comment.