diff --git a/src/develop.rs b/src/develop.rs index 9e09770b9..6d01822b8 100644 --- a/src/develop.rs +++ b/src/develop.rs @@ -38,8 +38,8 @@ impl InstallBackend { } } - fn version(&self, python_path: &Path) -> Result { - let mut cmd = self.make_command(python_path); + fn version(&self, python_path: &Path, venv_dir: &Path) -> Result { + let mut cmd = self.make_command(python_path, venv_dir); let output = cmd .arg("--version") .output() @@ -62,12 +62,12 @@ impl InstallBackend { } /// check whether this install backend supports `show --files`. Returns Ok(()) if it does. - fn check_supports_show_files(&self, python_path: &Path) -> Result<()> { + fn check_supports_show_files(&self, python_path: &Path, venv_dir: &Path) -> Result<()> { match self { InstallBackend::Pip { .. } => Ok(()), InstallBackend::Uv { .. } => { // https://github.com/astral-sh/uv/releases/tag/0.4.25 - let version = self.version(python_path)?; + let version = self.version(python_path, venv_dir)?; if version < semver::Version::new(0, 4, 25) { bail!( "uv >= 0.4.25 is required for `show --files`. Version {} was found.", @@ -87,7 +87,7 @@ impl InstallBackend { } } - fn make_command(&self, python_path: &Path) -> Command { + fn make_command(&self, python_path: &Path, venv_dir: &Path) -> Command { match self { InstallBackend::Pip { path } => match &path { Some(path) => { @@ -106,6 +106,9 @@ impl InstallBackend { InstallBackend::Uv { path, args } => { let mut cmd = Command::new(path); cmd.args(args).arg("pip"); + if std::env::var_os("VIRTUAL_ENV").is_none() { + cmd.env("VIRTUAL_ENV", venv_dir); + } cmd } } @@ -225,6 +228,7 @@ fn install_dependencies( build_context: &BuildContext, extras: &[String], interpreter: &PythonInterpreter, + venv_dir: &Path, install_backend: &InstallBackend, ) -> Result<()> { if !build_context.metadata24.requires_dist.is_empty() { @@ -256,7 +260,7 @@ fn install_dependencies( pkg.to_string() })); let status = install_backend - .make_command(&interpreter.executable) + .make_command(&interpreter.executable, venv_dir) .args(&args) .status() .context("Failed to run pip install")?; @@ -275,7 +279,7 @@ fn install_wheel( wheel_filename: &Path, install_backend: &InstallBackend, ) -> Result<()> { - let mut cmd = install_backend.make_command(python); + let mut cmd = install_backend.make_command(python, venv_dir); let output = cmd .args(["install", "--no-deps", "--force-reinstall"]) .arg(dunce::simplified(wheel_filename)) @@ -305,7 +309,7 @@ fn install_wheel( String::from_utf8_lossy(&output.stderr).trim(), ); } - if let Err(err) = configure_as_editable(build_context, python, install_backend) { + if let Err(err) = configure_as_editable(build_context, python, venv_dir, install_backend) { eprintln!("⚠️ Warning: failed to set package as editable: {}", err); } Ok(()) @@ -322,11 +326,12 @@ fn install_wheel( fn configure_as_editable( build_context: &BuildContext, python: &Path, + venv_dir: &Path, install_backend: &InstallBackend, ) -> Result<()> { println!("✏️ Setting installed package as editable"); - install_backend.check_supports_show_files(python)?; - let mut cmd = install_backend.make_command(python); + install_backend.check_supports_show_files(python, venv_dir)?; + let mut cmd = install_backend.make_command(python, venv_dir); let cmd = cmd.args(["show", "--files", &build_context.metadata24.name]); debug!("running {:?}", cmd); let output = cmd.output()?; @@ -460,7 +465,13 @@ pub fn develop(develop_options: DevelopOptions, venv_dir: &Path) -> Result<()> { } }; - install_dependencies(&build_context, &extras, &interpreter, &install_backend)?; + install_dependencies( + &build_context, + &extras, + &interpreter, + venv_dir, + &install_backend, + )?; let wheels = build_context.build_wheels()?; if !skip_install {