0021: Python interpreters chosen by the user, Pyright, pytest JUnit results
- Status: Proposed (implemented in Phase 2, task 014)
- Date: 2026-12-05
Context
Python is the third complete slice. Unlike Cargo and the .NET SDK, Python has no single toolchain: each project usually has its own virtual environment, and which interpreter runs decides which packages exist. Asking an interpreter for its version or packages runs it, and an interpreter inside the workspace is workspace code. Packaging metadata can be computed by a build backend or setup.py, which also runs code. Pyright, the most complete open Python server, reads the interpreter from client settings that it pulls with workspace/configuration.
Decision
- Static discovery.
pyproject.toml([project]name andrequires-python), import packages (folders with__init__.py, flat orsrclayout), runnable packages (__main__.py) and atests/testfolder withtest_*.py.setup.py,setup.cfgand dynamic metadata are reported as unresolved, never run. - The interpreter is the user's choice, per project. Candidates are listed from the file system only:
.venv,venvandenvin the project and up to two parent folders (theirpyvenv.cfggives the version and the base interpreter), andpython3/pythononPATH. A choice is validated without running it (it exists, is a file named like an interpreter, and its environment's base interpreter still exists) and saved in the user's configuration folder (toolchains.toml), never in the workspace. Without a choice, tasks use the interpreter onPATH. - A generic host mechanism.
ToolchainCandidate,toolchain_candidates,validate_toolchainandserver_settingsare provider methods; the core stores the choice, hands it to providers inProjectDescriptor::toolchainandDebugConfig::toolchain, and restarts only the language service rooted at that project when its settings change. No Python code is in the core. - Pyright through standard settings.
pyright-langserver --stdio, user-installed. The client answersworkspace/configurationfrom the provider's settings by section:python.pythonPath(the chosen interpreter) andpython.analysis(open-files diagnostics, search paths, library types). - Tasks run the chosen interpreter with typed argv.
python -m <package>per runnable package,python -m pytest <tests> --junitxml=<temp file>andpython -m unittest discover -v.PYTHONDONTWRITEBYTECODEand-p no:cacheproviderkeep the project free of caches;srcis put onPYTHONPATHfor thesrclayout. Tracebacks become problems; pytest results come from its JUnit report (read without DTDs, then removed); unittest results from its verbose lines. A missing pytest gets guidance; nothing is installed. - debugpy for debug plans.
python -m debugpy.adapterwith the chosen interpreter, speaking DAP over stdio; the adapter reaches the program over loopback only. Refused when debugpy is not in the environment. The DAP client is task 015.
Alternatives considered
- Ask the interpreter (
python -c "import sys; ...") for version and paths. Exact, but runs a program that may be inside the workspace before the user picked it.pyvenv.cfggives the version of environments, which is the common case. - Pick
.venvautomatically. Convenient, but it would run workspace code on open. The Tasks panel offers it in one click instead. - basedpyright, pylsp, Jedi. basedpyright speaks the same protocol and settings and can be configured instead; pylsp and Jedi are less complete for types.
- Parse pytest's console output. It changes between versions and plugins; JUnit XML is stable.
Consequences
- New dependency:
tree-sitter-python0.25 (MIT). - Server settings are now part of
ServerConfig; a change restarts only the affected service. - Environments the user creates elsewhere (conda, pyenv, Poetry's cache folder) are chosen by path, not listed yet.