Skip to content

Template Sync: Use @vscode/python-environmentΒ #433

@github-actions

Description

@github-actions

πŸ”„ Template Sync Required

Changes from the upstream vscode-python-tools-extension-template have not yet been incorporated into this repository.

Source PR

Summary

The template switched from manually loading the ms-python.vscode-python-envs extension via extensions.getExtension() and a custom local typings file, to using the official @vscode/python-environments npm package. The package is hosted on Azure DevOps (pkgs.dev.azure.com/azure-public/vside/_packaging/python-environments) and provides PythonEnvironmentApi and PythonEnvironments as first-class exports. This removes the need for the custom src/typings/pythonEnvironments.d.ts declarations and the manual extension-activation boilerplate.

Files with missing changes

  • src/common/python.ts β€” Still uses PythonEnvironmentsAPI from ../typings/pythonEnvironments and loads the envs extension via extensions.getExtension(PYTHON_ENVIRONMENTS_EXTENSION_ID) + manual extension.activate(). The template now uses PythonEnvironments.api() from @vscode/python-environments and the typed PythonEnvironmentApi interface, removing the manual extension-load path.
  • src/typings/pythonEnvironments.d.ts β€” Local hand-written type declarations that become redundant once @vscode/python-environments is added as a dependency. In the template this file was deleted entirely.
  • package.json β€” Does not declare "@vscode/python-environments" as a runtime dependency.
  • .npmrc β€” Currently overrides the registry to https://registry.npmjs.org/ for all scopes. The @vscode/python-environments package lives on Azure DevOps and requires a scope-specific registry entry (@vscode:registry=...).

Suggested fix

1. .npmrc β€” Add a scope-specific registry entry while keeping the existing default:

-registry=https://registry.npmjs.org/
-always-auth=false
+registry=https://registry.npmjs.org/
+always-auth=false
+`@vscode`:registry=(pkgs.dev.azure.com/redacted)

2. package.json β€” Add the new runtime dependency:

 "dependencies": {
+    "`@vscode/python-environments`": "^1.0.0",
     "`@vscode/python-extension`": "^1.0.6",

3. src/common/python.ts β€” Replace manual extension loading with PythonEnvironments.api(). The vscode-flake8 implementation has additional logic (version checking with semver, convertToResolvedEnvironment, etc.) that must be preserved. Only the environment-API initialisation block needs to change:

-import type { PythonEnvironment, PythonEnvironmentsAPI } from '../typings/pythonEnvironments';
+import { PythonEnvironmentApi, PythonEnvironments } from '`@vscode/python-environments`';

-const PYTHON_ENVIRONMENTS_EXTENSION_ID = 'ms-python.vscode-python-envs';
-
-let _envsApi: PythonEnvironmentsAPI | undefined;
-async function getEnvironmentsExtensionAPI(): Promise(PythonEnvironmentsAPI | undefined) {
+let _envsApi: PythonEnvironmentApi | undefined;
+async function getEnvironmentsExtensionAPI(): Promise(PythonEnvironmentApi | undefined) {
     if (_envsApi) {
         return _envsApi;
     }
-    const extension = extensions.getExtension(PYTHON_ENVIRONMENTS_EXTENSION_ID);
-    if (!extension) {
+    try {
+        _envsApi = await PythonEnvironments.api();
+    } catch {
         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);
-        return undefined;
-    }
+    return _envsApi;
 }

⚠️ Note: The PythonEnvironmentApi from the npm package may expose a different shape than the hand-written PythonEnvironmentsAPI typings (e.g., different field names on PythonEnvironment, presence/absence of resolveEnvironment). Review the @vscode/python-environments package types carefully before removing src/typings/pythonEnvironments.d.ts and adapting the callers (getInterpreterDetails, resolveInterpreter, event handlers).

4. src/typings/pythonEnvironments.d.ts β€” Remove once the package types have been verified to cover all usage.

Files skipped

  • package-lock.json β€” Auto-generated; will be updated by npm install after package.json changes.

πŸ€– This issue was auto-generated by the extension-template-sync workflow.

Generated by Extension Template Sync Β· β—·

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions