From e1f73a61fe04efc4df1d4a60ed2d0925eac21995 Mon Sep 17 00:00:00 2001 From: Xin Zhao Date: Thu, 15 Jan 2026 21:59:59 +0800 Subject: [PATCH] languages: Support terminal auto-activation for `poetry` managed Python environment (#46900) Although `poetry` may store virtual environments in a global cache directory (unlike the standard project-local `.venv`), the internal directory structure of these environments remains consistent with standard `venv` or `uv` environments. Since our existing activation logic for `venv` environments relies on relative paths within the environment root, it is naturally compatible with `poetry` environments. Once the toolchain locates the environment's root directory, the activation scripts can be applied without further modification. Testing: - Verified on Windows: Confirmed working across `PowerShell`, `Pwsh`, and `Cmd` for global poetry environments. - Observation: When using an in-project `.venv` directory, the toolchain may categorize the environment as `venv`-managed instead of `poetry`-managed. While this behavior relates to the toolchain's discovery logic, the activation itself remains fully functional as the underlying structure is compatible. Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/languages/src/python.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index 81a9971b2743d6c27368bbaf3bb6e770b2aeccc1..8195ea554b537cf723904b440b77efc1a659ac01 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -1362,7 +1362,8 @@ impl ToolchainLister for PythonToolchainProvider { PythonEnvironmentKind::Venv | PythonEnvironmentKind::VirtualEnv | PythonEnvironmentKind::Uv - | PythonEnvironmentKind::UvWorkspace, + | PythonEnvironmentKind::UvWorkspace + | PythonEnvironmentKind::Poetry, ) => { if let Some(activation_scripts) = &toolchain.activation_scripts { if let Some(activate_script_path) = activation_scripts.get(&shell) { @@ -1424,7 +1425,8 @@ async fn venv_to_toolchain(venv: PythonEnvironment, fs: &dyn Fs) -> Option resolve_venv_activation_scripts(&venv, fs, &mut activation_scripts).await, _ => {} }