Skip to content
Open
31 changes: 31 additions & 0 deletions api/package-lock.json

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

3 changes: 3 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"@types/node": "^22.0.0",
"@types/vscode": "^1.99.0",
"typescript": "^5.1.3"
},
"dependencies": {
"@renovatebot/pep440": "^3.1.0"
}
}
54 changes: 53 additions & 1 deletion api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
* This is the public API for other extensions to interact with the Python Environments extension.
*/

export type { Pep440Version } from '@renovatebot/pep440';
import type { Pep440Version } from '@renovatebot/pep440';
/**
* The path to an icon, or a theme-specific configuration of icons.
*/
Expand Down Expand Up @@ -691,6 +693,35 @@ export interface PackageManager {
* @returns A promise that resolves when the cache is cleared.
*/
clearCache?(): Promise<void>;

/**
* Returns the version of the underlying package management tool (e.g., pip, conda).
* @param environment - The Python environment context.
* @returns A promise that resolves to a {@link Pep440Version} object, or `undefined` if not available.
*/
getVersion?(environment: PythonEnvironment): Promise<Pep440Version | undefined>;

/**
* Retrieves the list of available versions for a given package.
* @param packageName - The name of the package to look up.
* @param environment - The Python environment context for the lookup.
* @returns A promise that resolves to an array of {@link Pep440Version} objects (newest first),
* or `undefined` if this manager does not support version listing.
*/
getAvailableVersions?(packageName: string, environment: PythonEnvironment): Promise<Pep440Version[] | undefined>;

Comment thread
edvilme marked this conversation as resolved.
/**
* Formats a versioned install specification for this package manager.
*
* Different package managers use different syntax (e.g. pip uses `name==version`,
* conda uses `name=version`). Implement this method to return the correct format.
* When absent, callers should default to `name==version`.
*
* @param packageName - The name of the package.
* @param version - The version string.
* @returns The install specification string (e.g. `"requests==2.31.0"` or `"requests=2.31.0"`).
*/
formatInstallSpec?(packageName: string, version: string): string;
}

/**
Expand Down Expand Up @@ -1059,12 +1090,33 @@ export interface PythonPackageManagementApi {
managePackages(environment: PythonEnvironment, options: PackageManagementOptions): Promise<void>;
}

export interface Pep440VersionApi {
/**
* Get the version of the package manager tool associated with the given environment.
*
* @param environment The Python Environment whose package manager version is requested.
* @returns The {@link Pep440Version} of the package manager tool, or `undefined` if not available.
*/
getPackageManagerVersion(environment: PythonEnvironment): Promise<Pep440Version | undefined>;

/**
* Get the list of available versions for a package from the package manager
* associated with the given environment.
*
* @param packageName The name of the package.
* @param environment The Python Environment context for the lookup.
* @returns An array of {@link Pep440Version} objects (newest first), or `undefined` if not supported.
*/
getAvailableVersions(packageName: string, environment: PythonEnvironment): Promise<Pep440Version[] | undefined>;
}
Comment thread
edvilme marked this conversation as resolved.

export interface PythonPackageManagerApi
extends
PythonPackageManagerRegistrationApi,
PythonPackageGetterApi,
PythonPackageManagementApi,
PythonPackageItemApi {}
PythonPackageItemApi,
Pep440VersionApi {}

export interface PythonProjectCreationApi {
/**
Expand Down
49 changes: 41 additions & 8 deletions package-lock.json

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

22 changes: 21 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 @@ -279,6 +282,12 @@
"category": "Python Envs",
"icon": "$(trash)"
},
{
"command": "python-envs.managePackageVersion",
"title": "%python-envs.managePackageVersion.title%",
"category": "Python Envs",
"icon": "$(gear)"
},
{
"command": "python-envs.copyEnvPath",
"title": "%python-envs.copyEnvPath.title%",
Expand Down Expand Up @@ -511,6 +520,11 @@
"group": "inline",
"when": "view == env-managers && viewItem =~ /.*pythonBrokenEnvironment.*/ && viewItem =~ /.*copied.*/"
},
{
"command": "python-envs.managePackageVersion",
"group": "inline",
"when": "view == env-managers && viewItem == python-package"
},
{
"command": "python-envs.uninstallPackage",
"group": "inline",
Expand Down Expand Up @@ -553,6 +567,11 @@
"command": "python-envs.revealProjectInExplorer",
"when": "view == python-projects && viewItem =~ /.*python-workspace.*/"
},
{
"command": "python-envs.managePackageVersion",
"group": "inline",
"when": "view == python-projects && viewItem == python-package"
},
{
"command": "python-envs.uninstallPackage",
"group": "inline",
Expand Down Expand Up @@ -714,6 +733,7 @@
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"@renovatebot/pep440": "^3.1.0",
"@vscode/extension-telemetry": "^0.9.7",
"@vscode/test-cli": "^0.0.10",
"dotenv": "^16.4.5",
Expand Down
Loading
Loading