Inject venv environment via the toolchain (#36576)

Instead of manually constructing the venv we now ask the python
toolchain for the relevant information, unifying the approach of vent
inspection

Fixes https://github.com/zed-industries/zed/issues/27350

Release Notes:

- Improved the detection of python virtual environments for terminals
and tasks in remote projects.
This commit is contained in:
Lukas Wirth
2025-08-28 14:40:43 +00:00
committed by GitHub
parent 24ee98b3e1
commit 835e5ba662
19 changed files with 725 additions and 672 deletions
+11 -1
View File
@@ -757,6 +757,7 @@ impl RemoteClient {
args: &[String],
env: &HashMap<String, String>,
working_dir: Option<String>,
activation_script: Option<String>,
port_forward: Option<(u16, String, u16)>,
) -> Result<CommandTemplate> {
let Some(connection) = self
@@ -766,7 +767,14 @@ impl RemoteClient {
else {
return Err(anyhow!("no connection"));
};
connection.build_command(program, args, env, working_dir, port_forward)
connection.build_command(
program,
args,
env,
working_dir,
activation_script,
port_forward,
)
}
pub fn upload_directory(
@@ -998,6 +1006,7 @@ pub(crate) trait RemoteConnection: Send + Sync {
args: &[String],
env: &HashMap<String, String>,
working_dir: Option<String>,
activation_script: Option<String>,
port_forward: Option<(u16, String, u16)>,
) -> Result<CommandTemplate>;
fn connection_options(&self) -> SshConnectionOptions;
@@ -1364,6 +1373,7 @@ mod fake {
args: &[String],
env: &HashMap<String, String>,
_: Option<String>,
_: Option<String>,
_: Option<(u16, String, u16)>,
) -> Result<CommandTemplate> {
let ssh_program = program.unwrap_or_else(|| "sh".to_string());
+10 -3
View File
@@ -30,7 +30,10 @@ use std::{
time::Instant,
};
use tempfile::TempDir;
use util::paths::{PathStyle, RemotePathBuf};
use util::{
get_default_system_shell,
paths::{PathStyle, RemotePathBuf},
};
pub(crate) struct SshRemoteConnection {
socket: SshSocket,
@@ -113,6 +116,7 @@ impl RemoteConnection for SshRemoteConnection {
input_args: &[String],
input_env: &HashMap<String, String>,
working_dir: Option<String>,
activation_script: Option<String>,
port_forward: Option<(u16, String, u16)>,
) -> Result<CommandTemplate> {
use std::fmt::Write as _;
@@ -134,6 +138,9 @@ impl RemoteConnection for SshRemoteConnection {
} else {
write!(&mut script, "cd; ").unwrap();
};
if let Some(activation_script) = activation_script {
write!(&mut script, " {activation_script};").unwrap();
}
for (k, v) in input_env.iter() {
if let Some((k, v)) = shlex::try_quote(k).ok().zip(shlex::try_quote(v).ok()) {
@@ -155,7 +162,8 @@ impl RemoteConnection for SshRemoteConnection {
write!(&mut script, "exec {shell} -l").unwrap();
};
let shell_invocation = format!("{shell} -c {}", shlex::try_quote(&script).unwrap());
let sys_shell = get_default_system_shell();
let shell_invocation = format!("{sys_shell} -c {}", shlex::try_quote(&script).unwrap());
let mut args = Vec::new();
args.extend(self.socket.ssh_args());
@@ -167,7 +175,6 @@ impl RemoteConnection for SshRemoteConnection {
args.push("-t".into());
args.push(shell_invocation);
Ok(CommandTemplate {
program: "ssh".into(),
args,