Skip to content

Conversation

@eleanorjboyd
Copy link
Member

@eleanorjboyd eleanorjboyd commented Oct 27, 2025

switch from using the Python extension apis to get the interpreter to instead using the Python Environments extension APIs (when available) as this will be the new best practice

closes #835

@eleanorjboyd eleanorjboyd changed the title Switch-env-api Switch to directly invoke python-environments-ext api Oct 27, 2025
@eleanorjboyd eleanorjboyd added the feature-request Request for new features or functionality label Oct 29, 2025
@eleanorjboyd eleanorjboyd requested a review from Copilot October 31, 2025 19:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors Python environment handling to support both the legacy Python extension API and a new Python Environments extension API. The changes enable runtime selection between the two APIs based on a configuration setting and extension availability.

Key Changes:

  • Introduced a new envExtApi.ts module containing the complete Python Environments extension API type definitions
  • Refactored python.ts to conditionally use either the legacy or new environment API via useEnvExtension() flag
  • Extracted legacy API implementation into legacyPython.ts for cleaner separation
  • Updated test suites to accommodate both API paths with new helper utilities
  • Modified debug adapter factory and configuration resolvers to work with the new PythonEnvironment type

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/extension/envExtApi.ts Added comprehensive API type definitions for the new Python Environments extension (1289 lines)
src/extension/common/python.ts Refactored to support dual API paths with conditional logic based on useEnvExtension()
src/extension/common/legacyPython.ts Extracted legacy Python extension API implementation from python.ts
src/extension/common/utilities.ts Added useEnvExtension() function to determine which API to use at runtime
src/extension/debugger/adapter/factory.ts Updated to use new PythonEnvironment type and added version parsing logic
src/extension/debugger/configuration/resolvers/base.ts Enhanced to resolve interpreter from program file when appropriate
src/extension/debugger/configuration/debugConfigurationService.ts Added interpreter resolution after variable substitution
src/extension/common/application/commands/reportIssueCommand.ts Updated to handle both environment API return types
src/test/unittest/common/pythonTrue.unit.test.ts New test suite for new environment extension path
src/test/unittest/common/pythonFalse.unit.test.ts New test suite for legacy extension path
src/test/unittest/common/helpers.ts Added buildPythonEnvironment() test helper function
src/test/unittest/adapter/factory.unit.test.ts Updated tests to use new PythonEnvironment type
src/test/unittest/configuration/resolvers/launch.unit.test.ts Updated to handle both API return types
src/test/unittest/common/application/commands/reportIssueCommand.unit.test.ts Updated mock interpreter structure
Comments suppressed due to low confidence (1)

src/test/unittest/common/pythonFalse.unit.test.ts:4

  • This expression has no effect.
('use strict');

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eleanorjboyd eleanorjboyd marked this pull request as ready for review November 3, 2025 19:38
@eleanorjboyd eleanorjboyd merged commit 0f1b4bc into microsoft:main Nov 3, 2025
18 checks passed
@eleanorjboyd eleanorjboyd deleted the switch-env-api branch November 3, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-request Request for new features or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update to use Python Environments Extension API (when applicable)

2 participants