Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@
"python-envs.workspaceSearchPaths": {
"type": "array",
"description": "%python-envs.workspaceSearchPaths.description%",
"default": [".venv", "*/.venv"],
"default": [
".venv",
"*/.venv"
],
"scope": "resource",
"items": {
"type": "string"
Expand Down Expand Up @@ -714,6 +717,7 @@
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"@renovatebot/pep440": "^4.2.4",
"@vscode/extension-telemetry": "^0.9.7",
"@vscode/test-cli": "^0.0.10",
"dotenv": "^16.4.5",
Expand Down
9 changes: 4 additions & 5 deletions src/common/extVersion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { compare as pep440Compare, valid as pep440Valid } from '@renovatebot/pep440';
import { PYTHON_EXTENSION_ID } from './constants';
import { getExtension } from './extension.apis';
import { traceError } from './logging';
Expand All @@ -8,11 +9,9 @@ export function ensureCorrectVersion() {
return;
}

const version = extension.packageJSON.version;
const parts = version.split('.');
const major = parseInt(parts[0]);
const minor = parseInt(parts[1]);
if (major >= 2025 || (major === 2024 && minor >= 23)) {
const version = pep440Valid(extension.packageJSON.version);
const minVersion = '2024.23.0';
if (version && pep440Compare(version, minVersion) >= 0) {
return;
}
traceError('Incompatible Python extension. Please update `ms-python.python` to version 2024.23 or later.');
Expand Down
9 changes: 2 additions & 7 deletions src/managers/builtin/pipUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as tomljs from '@iarna/toml';
import { valid as pep440Valid } from '@renovatebot/pep440';
import * as fse from 'fs-extra';
import * as path from 'path';
import { l10n, LogOutputChannel, ProgressLocation, QuickInputButtons, QuickPickItem, Uri, window } from 'vscode';
Expand Down Expand Up @@ -56,13 +57,7 @@ export function validatePyprojectToml(toml: PyprojectToml): string | undefined {
if (version.length === 0) {
return l10n.t('Version cannot be empty in pyproject.toml.');
}
// PEP 440 version regex. Versions must follow PEP 440 format (e.g., "1.0.0", "2.1a3").
// See https://peps.python.org/pep-0440/
// This regex is adapted from the official python 'packaging' library:
// https://github.com/pypa/packaging/blob/main/src/packaging/version.py
const versionRegex =
/^v?([0-9]+!)?([0-9]+(?:\.[0-9]+)*)(?:[-_.]?(a|b|c|rc|alpha|beta|pre|preview)[-_.]?([0-9]+)?)?(?:(?:-([0-9]+))|(?:[-_.]?(post|rev|r)[-_.]?([0-9]+)?))?(?:[-_.]?(dev)[-_.]?([0-9]+)?)?(?:\+([a-z0-9]+(?:[-_.][a-z0-9]+)*))?$/i;
if (!versionRegex.test(version)) {
if (!pep440Valid(version)) {
return l10n.t('Invalid version "{0}" in pyproject.toml.', version);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/managers/builtin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
NativePythonEnvironmentKind,
NativePythonFinder,
} from '../common/nativePythonFinder';
import { shortVersion, sortEnvironments } from '../common/utils';
import { shortenVersionString, sortEnvironments } from '../common/utils';
import { runPython, runUV, shouldUseUv } from './helpers';
import { parsePipListJson, PipPackage } from './pipListUtils';

Expand Down Expand Up @@ -80,7 +80,7 @@ function getKindName(kind: NativePythonEnvironmentKind | undefined): string | un
function getPythonInfo(env: NativeEnvInfo): PythonEnvironmentInfo {
if (env.executable && env.version && env.prefix) {
const kindName = getKindName(env.kind);
const sv = shortVersion(env.version);
const sv = shortenVersionString(env.version);
const name = kindName ? `Python ${sv} (${kindName})` : `Python ${sv}`;
const displayName = kindName ? `Python ${sv} (${kindName})` : `Python ${sv}`;
const shortDisplayName = kindName ? `${sv} (${kindName})` : `${sv}`;
Expand Down
4 changes: 2 additions & 2 deletions src/managers/builtin/venvManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { showErrorMessage, showInformationMessage, withProgress } from '../../co
import { findParentIfFile } from '../../features/envCommands';
import { getProjectFsPathForScope, tryFastPathGet } from '../common/fastPath';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { getLatest, shortVersion, sortEnvironments } from '../common/utils';
import { getLatest, shortenVersionString, sortEnvironments } from '../common/utils';
import { promptInstallPythonViaUv } from './uvPythonInstaller';
import {
clearVenvCache,
Expand Down Expand Up @@ -117,7 +117,7 @@ export class VenvManager implements EnvironmentManager {
description: l10n.t('Create a virtual environment in workspace root'),
detail: l10n.t(
'Uses Python version {0} and installs workspace dependencies.',
shortVersion(this.globalEnv.version),
shortenVersionString(this.globalEnv.version),
),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/managers/builtin/venvUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
NativePythonEnvironmentKind,
NativePythonFinder,
} from '../common/nativePythonFinder';
import { getShellActivationCommands, shortVersion, sortEnvironments } from '../common/utils';
import { getShellActivationCommands, shortenVersionString, sortEnvironments } from '../common/utils';
import { runPython, runUV, shouldUseUv } from './helpers';
import { getProjectInstallable, PipPackages, shouldProceedAfterPyprojectValidation } from './pipUtils';
import { resolveSystemPythonEnvironmentPath } from './utils';
Expand Down Expand Up @@ -164,7 +164,7 @@ async function getPythonInfo(env: NativeEnvInfo): Promise<PythonEnvironmentInfo>

if (env.executable && env.version && env.prefix) {
const venvName = env.name ?? getName(env.executable);
const sv = shortVersion(env.version);
const sv = shortenVersionString(env.version);
const name = `${venvName} (${sv})`;
let description = undefined;
if (env.kind === NativePythonEnvironmentKind.venvUv) {
Expand Down
Loading
Loading