From 53cfb578e8ecdeb6206e06a6814aae73c8c610bc Mon Sep 17 00:00:00 2001 From: Torrat <74322746+TorratDev@users.noreply.github.com> Date: Fri, 3 Jan 2025 23:56:31 +0100 Subject: [PATCH] python: Adjust binary path based on OS (#22587) Closes #ISSUE - #21452 Describe the bug / provide steps to reproduce it Language server error: pylsp failed to spawn command. path: "C:\Users\AppData\Local\Zed\languages\pylsp\pylsp-venv\bin\pylsp", working directory: "D:\Coding\Python", args: [] -- stderr-- Environment - Windows 11 - python Release Notes: - Windows: Fixed the path building used to run `pip` commands in the venv generated on Windows 11. --------- Co-authored-by: Marshall Bowers --- crates/languages/src/python.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index 607140e33af0f1e3d4dab7fba5e4f3d02fc31701..9c22b54bc87f6146653de8efa4f973ad8b128ee8 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -770,6 +770,12 @@ impl PyLspAdapter { } } +const BINARY_DIR: &str = if cfg!(target_os = "windows") { + "Scripts" +} else { + "bin" +}; + #[async_trait(?Send)] impl LspAdapter for PyLspAdapter { fn name(&self) -> LanguageServerName { @@ -811,7 +817,7 @@ impl LspAdapter for PyLspAdapter { delegate: &dyn LspAdapterDelegate, ) -> Result { let venv = self.base_venv(delegate).await.map_err(|e| anyhow!(e))?; - let pip_path = venv.join("bin").join("pip3"); + let pip_path = venv.join(BINARY_DIR).join("pip3"); ensure!( util::command::new_smol_command(pip_path.as_path()) .arg("install") @@ -842,7 +848,7 @@ impl LspAdapter for PyLspAdapter { .success(), "pylsp-mypy installation failed" ); - let pylsp = venv.join("bin").join("pylsp"); + let pylsp = venv.join(BINARY_DIR).join("pylsp"); Ok(LanguageServerBinary { path: pylsp, env: None, @@ -856,7 +862,7 @@ impl LspAdapter for PyLspAdapter { delegate: &dyn LspAdapterDelegate, ) -> Option { let venv = self.base_venv(delegate).await.ok()?; - let pylsp = venv.join("bin").join("pylsp"); + let pylsp = venv.join(BINARY_DIR).join("pylsp"); Some(LanguageServerBinary { path: pylsp, env: None,