Skip to main content

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 and requires-python), import packages (folders with __init__.py, flat or src layout), runnable packages (__main__.py) and a tests/test folder with test_*.py. setup.py, setup.cfg and 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, venv and env in the project and up to two parent folders (their pyvenv.cfg gives the version and the base interpreter), and python3/python on PATH. 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 on PATH.
  • A generic host mechanism. ToolchainCandidate, toolchain_candidates, validate_toolchain and server_settings are provider methods; the core stores the choice, hands it to providers in ProjectDescriptor::toolchain and DebugConfig::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 answers workspace/configuration from the provider's settings by section: python.pythonPath (the chosen interpreter) and python.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> and python -m unittest discover -v. PYTHONDONTWRITEBYTECODE and -p no:cacheprovider keep the project free of caches; src is put on PYTHONPATH for the src layout. 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.adapter with 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.cfg gives the version of environments, which is the common case.
  • Pick .venv automatically. 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-python 0.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.