diff --git a/.npmrc b/.npmrc index 6d6c884..8e6d762 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,4 @@ +@vscode:registry=https://pkgs.dev.azure.com/azure-public/vside/_packaging/python-environments/npm/registry/ # Force public npm registry to avoid CI auth (E401) when no token is provided registry=https://registry.npmjs.org/ # Do not require auth for public installs diff --git a/package-lock.json b/package-lock.json index af3890e..6bac120 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "2025.3.0", "license": "MIT", "dependencies": { + "@vscode/python-environments": "^1.0.0", "@vscode/python-extension": "^1.0.6", "fs-extra": "^11.3.1", "minimatch": "^10.2.4", @@ -1292,6 +1293,16 @@ "dev": true, "license": "ISC" }, + "node_modules/@vscode/python-environments": { + "version": "1.0.0", + "resolved": "https://pkgs.dev.azure.com/azure-public/vside/_packaging/python-environments/npm/registry/@vscode/python-environments/-/python-environments-1.0.0.tgz", + "integrity": "sha1-AQxJi6ysjdysdHVWlc/H3XEbHfU=", + "license": "MIT", + "engines": { + "node": ">=22.21.1", + "vscode": "^1.110.0" + } + }, "node_modules/@vscode/python-extension": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@vscode/python-extension/-/python-extension-1.0.6.tgz", diff --git a/package.json b/package.json index ab511a4..da9a627 100644 --- a/package.json +++ b/package.json @@ -215,6 +215,7 @@ ] }, "dependencies": { + "@vscode/python-environments": "^1.0.0", "@vscode/python-extension": "^1.0.6", "fs-extra": "^11.3.1", "minimatch": "^10.2.4", diff --git a/src/common/python.ts b/src/common/python.ts index 210670d..939e05f 100644 --- a/src/common/python.ts +++ b/src/common/python.ts @@ -2,11 +2,11 @@ // Licensed under the MIT License. /* eslint-disable @typescript-eslint/naming-convention */ -import { commands, Disposable, Event, EventEmitter, extensions, Uri } from 'vscode'; +import { PythonEnvironmentApi, PythonEnvironment, PythonEnvironments } from '@vscode/python-environments'; +import { commands, Disposable, Event, EventEmitter, Uri } from 'vscode'; import { traceError, traceLog } from './logging'; import { PythonExtension, ResolvedEnvironment } from '@vscode/python-extension'; import * as semver from 'semver'; -import type { PythonEnvironment, PythonEnvironmentsAPI } from '../typings/pythonEnvironments'; import { PYTHON_MAJOR, PYTHON_MINOR, PYTHON_VERSION } from './constants'; import { getProjectRoot } from './utilities'; @@ -56,32 +56,17 @@ async function getPythonExtensionAPI(): Promise { return _api; } -const PYTHON_ENVIRONMENTS_EXTENSION_ID = 'ms-python.vscode-python-envs'; - -let _envsApi: PythonEnvironmentsAPI | undefined; -async function getEnvironmentsExtensionAPI(): Promise { +let _envsApi: PythonEnvironmentApi | undefined; +async function getEnvironmentsExtensionAPI(): Promise { if (_envsApi) { return _envsApi; } - const extension = extensions.getExtension(PYTHON_ENVIRONMENTS_EXTENSION_ID); - if (!extension) { - return undefined; - } try { - if (!extension.isActive) { - await extension.activate(); - } - const api = extension.exports; - if (!api) { - traceError('Python environments extension did not provide any exports.'); - return undefined; - } - _envsApi = api as PythonEnvironmentsAPI; - return _envsApi; - } catch (ex) { - traceError('Failed to activate or retrieve API from Python environments extension.', ex as Error); + _envsApi = await PythonEnvironments.api(); + } catch { return undefined; } + return _envsApi; } function sameInterpreter(a: string[], b: string[]): boolean { diff --git a/src/typings/pythonEnvironments.d.ts b/src/typings/pythonEnvironments.d.ts deleted file mode 100644 index f36fe6e..0000000 --- a/src/typings/pythonEnvironments.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -/* eslint-disable @typescript-eslint/naming-convention */ -import { Event, Uri } from 'vscode'; - -export interface PythonCommandRunConfiguration { - executable: string; - args?: string[]; -} - -export interface PythonEnvironmentExecutionInfo { - run: PythonCommandRunConfiguration; - activatedRun?: PythonCommandRunConfiguration; - activation?: PythonCommandRunConfiguration[]; -} - -export interface PythonEnvironmentInfo { - name: string; - displayName: string; - version: string; - environmentPath: Uri; - execInfo: PythonEnvironmentExecutionInfo; - sysPrefix: string; -} - -export interface PythonEnvironmentId { - id: string; - managerId: string; -} - -export interface PythonEnvironment extends PythonEnvironmentInfo { - envId: PythonEnvironmentId; -} - -export type GetEnvironmentScope = undefined | Uri; - -export interface DidChangeEnvironmentEventArgs { - uri: Uri | undefined; - old: PythonEnvironment | undefined; - new: PythonEnvironment | undefined; -} - -export type ResolveEnvironmentContext = Uri; - -export interface PythonEnvironmentsAPI { - getEnvironment(scope: GetEnvironmentScope): Promise; - resolveEnvironment(context: ResolveEnvironmentContext): Promise; - onDidChangeEnvironment: Event; -}