Use exact per-file environments for Python files (PEP 723 PR 19) - #26129
Use exact per-file environments for Python files (PEP 723 PR 19)#26129Stella Huang (StellaHuang95) wants to merge 3 commits into
Conversation
Resolve debugger programs and Pylance Python-file configuration against the exact file resource without publishing false workspace interpreter changes. Preserve workspace fallback and activate differing program environments. Part of microsoft/vscode-python-environments#1602. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2ea8f5e to
e413c74
Compare
|
🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR. |
|
Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Result: Summary: Verification could not execute because no trusted sandbox image is configured for `microsoft/vscode-python`, and local execution was not authorized. The PR adds eight focused unit tests covering exact interpreter lookup, debugger selection, activation, and Pylance configuration. None could be run, so no pass/fail confidence is available. Two newly introduced debugger resolution paths appear uncovered. Test runs: 1 not run
|
Bill Schnurr (bschnurr)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Clarify why the workspace/configuration handler resolves the interpreter for the exact .py file (exactResource) rather than its folder: it honors a per-file environment such as a PEP 723 inline-script env for the language client this extension hosts, and only diverges from folder resolution when the Python Environments extension is in use. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Result: Summary: Verification was blocked because no trusted sandbox image is configured for `microsoft/vscode-python`, and local execution was not authorized. No tests meaningfully ran. The PR adds eight focused unit tests, but `${file}` debugger program resolution lacks explicit coverage. Test runs: 1 not run
|
The debug resolver now resolves \/\ to a program URI and looks up the interpreter for that file. To avoid changing behavior for users who are not using the environments extension (e.g. multi-root debugging of a file that lives in a different folder than the launch config), only take the program-scoped path when useEnvExtension() is true; otherwise fall back to the historical workspace-folder resolution. Environments-extension users still get per-file (inline-script) resolution. Stub useEnvExtension() in the existing program-scoped resolver tests and add a test covering the gated fallback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Result: Summary: Verification could not run because no trusted sandbox image is configured for `microsoft/vscode-python`, and local execution was not authorized. The PR adds nine focused unit tests covering exact interpreter lookup, debugger selection/fallback, named workspaces, and activation. One documented path, `${file}` debugger program resolution, has no test coverage I could find. Test runs: 1 not run
|
Roadmap context
This is cross-repository PR 19 in the PEP 723 roadmap. It closes the Python extension's per-file lookup gaps for debugging and Pylance configuration.
Why this PR
IInterpreterService.getActiveInterpreter(resource)normally shares in-flight, timeout, and last-known state by workspace folder. A file URI can therefore receive the workspace interpreter when a workspace lookup is already running or when exact environment resolution exceeds the timeout.That breaks two per-file consumers:
workspace/configurationrequest can receive a cached workspace interpreter.The exact lookup must also avoid publishing a file interpreter as a workspace-wide interpreter change.
What this PR does
exactResourceoption toIInterpreterService.${file};${workspaceFolder};${workspaceFolder:name}.pythonPathand command-valuedpython..py-scoped Pylance configuration requests; workspace-level requests retain the existing cached fast path.Lookup semantics
pythonconfig for a.pyURIPerformance and safety
.pyconfiguration scopes.User impact
Users without a per-file environment retain the same interpreter and debugger behavior. When a Python file has a distinct environment, Pylance configuration and debugger launch consistently use that file's interpreter rather than a workspace-cached value.
Tests
TelemetryReporterimport errors in untouched files.Scope and follow-up
This PR does not implement Pylance's open-file rerouting notification. Live movement and reanalysis after a per-file environment change remain in PR 18.