Skip to content

Commit 7b0e8cb

Browse files
committed
Address pr comments
1 parent 0a0b999 commit 7b0e8cb

5 files changed

Lines changed: 88 additions & 6 deletions

File tree

api/package-lock.json

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
},
3636
"devDependencies": {
3737
"@types/node": "^22.0.0",
38+
"@types/semver": "^7.5.8",
3839
"@types/vscode": "^1.99.0",
3940
"typescript": "^5.1.3"
41+
},
42+
"dependencies": {
43+
"semver": "^7.6.0"
4044
}
4145
}

api/src/main.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
import type * as semver from 'semver';
45
import {
56
Disposable,
67
Event,
@@ -691,6 +692,22 @@ export interface PackageManager {
691692
* @returns A promise that resolves when the cache is cleared.
692693
*/
693694
clearCache?(): Promise<void>;
695+
696+
/**
697+
* Returns the version of the underlying package management tool (e.g., pip, conda).
698+
* @param environment - The Python environment context.
699+
* @returns A promise that resolves to a SemVer object, or `undefined` if not available.
700+
*/
701+
getVersion?(environment: PythonEnvironment): Promise<semver.SemVer | undefined>;
702+
703+
/**
704+
* Retrieves the list of available versions for a given package.
705+
* @param packageName - The name of the package to look up.
706+
* @param environment - The Python environment context for the lookup.
707+
* @returns A promise that resolves to an array of version strings (newest first),
708+
* or `undefined` if this manager does not support version listing.
709+
*/
710+
getAvailableVersions?(packageName: string, environment: PythonEnvironment): Promise<string[] | undefined>;
694711
}
695712

696713
/**
@@ -1059,12 +1076,33 @@ export interface PythonPackageManagementApi {
10591076
managePackages(environment: PythonEnvironment, options: PackageManagementOptions): Promise<void>;
10601077
}
10611078

1079+
export interface PythonPackageVersionApi {
1080+
/**
1081+
* Get the version of the package manager tool associated with the given environment.
1082+
*
1083+
* @param environment The Python Environment whose package manager version is requested.
1084+
* @returns The SemVer version of the package manager tool, or `undefined` if not available.
1085+
*/
1086+
getPackageManagerVersion(environment: PythonEnvironment): Promise<semver.SemVer | undefined>;
1087+
1088+
/**
1089+
* Get the list of available versions for a package from the package manager
1090+
* associated with the given environment.
1091+
*
1092+
* @param packageName The name of the package.
1093+
* @param environment The Python Environment context for the lookup.
1094+
* @returns An array of version strings (newest first), or `undefined` if not supported.
1095+
*/
1096+
getAvailableVersions(packageName: string, environment: PythonEnvironment): Promise<string[] | undefined>;
1097+
}
1098+
10621099
export interface PythonPackageManagerApi
10631100
extends
10641101
PythonPackageManagerRegistrationApi,
10651102
PythonPackageGetterApi,
10661103
PythonPackageManagementApi,
1067-
PythonPackageItemApi {}
1104+
PythonPackageItemApi,
1105+
PythonPackageVersionApi {}
10681106

10691107
export interface PythonProjectCreationApi {
10701108
/**

src/features/envCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export async function handlePackageVersionManagement(context: unknown, em: Envir
338338
if (availableVersions && availableVersions.length > 0) {
339339
const items = availableVersions.map((v) => ({
340340
label: v,
341-
description: v === pkg.version ? '$(check)' : undefined,
341+
description: v === pkg.version ? `$(check) ${l10n.t('Installed')}` : undefined,
342342
}));
343343

344344
const selected = await showQuickPick(items, {

src/managers/builtin/pipManager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
PythonEnvironment,
2121
PythonEnvironmentApi,
2222
} from '../../api';
23-
import { runPython, runUV, shouldUseUv } from './helpers';
23+
import { runProcessCaptureAll, runPython, runUV, shouldUseUv } from './helpers';
2424
import { getWorkspacePackagesToInstall } from './pipUtils';
2525
import { managePackages, refreshPackages } from './utils';
2626
import { VenvManager } from './venvManager';
@@ -188,13 +188,12 @@ export class PipPackageManager implements PackageManager, Disposable {
188188

189189
// pip <= 20.3.4 - use `pip install <package>==__invalid__` to get available versions from error message.
190190
if (pipVersion && semver.lte(pipVersion, '20.3.4')) {
191-
const output = await runPython(
191+
const result = await runProcessCaptureAll(
192192
python,
193193
['-m', 'pip', 'install', `${packageName}==__invalid__`],
194-
undefined,
195194
this.log,
196195
);
197-
return parsePipInstallVersions(output);
196+
return parsePipInstallVersions(result.stdout + result.stderr);
198197
}
199198
} catch {
200199
return undefined;

0 commit comments

Comments
 (0)