Brett Cannon: Why I wrote PEP ... Note

Brett Cannon: Why I wrote PEP 832 -- virtual environment discovery

Tools like VS Code struggle to identify a project's Python environment, hindering essential functions like code execution and dependency analysis. This challenge arises because editors lack a universal method to detect which workflow tool a project employs or where its virtual environments are located. When a project is first opened, VS Code cannot reliably determine if the user prefers Hatch, Poetry, uv, or a custom solution. Current methods often rely on guessing based on pyproject.toml, which depends on maintaining an exact list of supported tools. Furthermore, workflow tools that store environments globally or allow shared environments complicate identification, especially when users manage numerous environments. A simple solution exists for environments stored locally in a .venv directory, offering basic functionality. However, for environments outside the project or when multiple exist, a dedicated file like proposed .python-envs could list their paths. To address tool preference, a [workflow] table in pyproject.toml is suggested to define how tools launch in a server mode, enabling communication via JSON-RPC based on the Workflow Server Protocol. This protocol allows tools to inform editors about available environments and manage their creation. An alternative involves establishing naming conventions for CLI tools that return necessary environment details. The author's motivation stems from a desire to simplify setup for all Python users, regardless of experience level, by minimizing manual environment management. This effort aims for solutions that are not VS Code-specific and can be adopted by other editors. Such a standardized communication protocol would elevate workflow tools beyond mere middleware, enabling broader editor support and reducing bespoke extension development.