Skip to content

Commit fe88cfe

Browse files
committed
Pass VIRTUAL_ENV to pip install/uv pip install
1 parent cbae302 commit fe88cfe

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/develop.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,6 @@ fn find_uv_bin() -> Result<(PathBuf, Vec<&'static str>)> {
125125
}
126126
}
127127

128-
fn check_pip_exists(python_path: &Path, pip_path: Option<&PathBuf>) -> Result<()> {
129-
let output = if let Some(pip_path) = pip_path {
130-
Command::new(pip_path).args(["--version"]).output()?
131-
} else {
132-
Command::new(python_path)
133-
.args(["-m", "pip", "--version"])
134-
.output()?
135-
};
136-
if output.status.success() {
137-
let version_str =
138-
str::from_utf8(&output.stdout).context("`pip --version` didn't return utf8 output")?;
139-
debug!(version = %version_str, "Found pip");
140-
Ok(())
141-
} else {
142-
bail!("`pip --version` failed with status: {}", output.status);
143-
}
144-
}
145-
146128
/// Detect the Python uv package
147129
fn find_uv_python(python_path: &Path) -> Result<(PathBuf, Vec<&'static str>)> {
148130
let output = Command::new(python_path)
@@ -162,6 +144,24 @@ fn find_uv_python(python_path: &Path) -> Result<(PathBuf, Vec<&'static str>)> {
162144
}
163145
}
164146

147+
fn check_pip_exists(python_path: &Path, pip_path: Option<&PathBuf>) -> Result<()> {
148+
let output = if let Some(pip_path) = pip_path {
149+
Command::new(pip_path).args(["--version"]).output()?
150+
} else {
151+
Command::new(python_path)
152+
.args(["-m", "pip", "--version"])
153+
.output()?
154+
};
155+
if output.status.success() {
156+
let version_str =
157+
str::from_utf8(&output.stdout).context("`pip --version` didn't return utf8 output")?;
158+
debug!(version = %version_str, "Found pip");
159+
Ok(())
160+
} else {
161+
bail!("`pip --version` failed with status: {}", output.status);
162+
}
163+
}
164+
165165
/// Check if a virtualenv is created by uv by reading pyvenv.cfg
166166
fn is_uv_venv(venv_dir: &Path) -> bool {
167167
let pyvenv_cfg = venv_dir.join("pyvenv.cfg");
@@ -224,7 +224,8 @@ pub struct DevelopOptions {
224224
fn install_dependencies(
225225
build_context: &BuildContext,
226226
extras: &[String],
227-
interpreter: &PythonInterpreter,
227+
python: &Path,
228+
venv_dir: &Path,
228229
install_backend: &InstallBackend,
229230
) -> Result<()> {
230231
if !build_context.metadata24.requires_dist.is_empty() {
@@ -256,12 +257,17 @@ fn install_dependencies(
256257
pkg.to_string()
257258
}));
258259
let status = install_backend
259-
.make_command(&interpreter.executable)
260+
.make_command(python)
260261
.args(&args)
262+
.env("VIRTUAL_ENV", venv_dir)
261263
.status()
262-
.context("Failed to run pip install")?;
264+
.with_context(|| format!("Failed to run {} install", install_backend.name()))?;
263265
if !status.success() {
264-
bail!(r#"pip install finished with "{}""#, status)
266+
bail!(
267+
r#"{} install finished with "{}""#,
268+
install_backend.name(),
269+
status
270+
)
265271
}
266272
}
267273
Ok(())
@@ -279,6 +285,7 @@ fn install_wheel(
279285
let output = cmd
280286
.args(["install", "--no-deps", "--force-reinstall"])
281287
.arg(dunce::simplified(wheel_filename))
288+
.env("VIRTUAL_ENV", venv_dir)
282289
.output()
283290
.context(format!(
284291
"{} install failed (ran {:?} with {:?})",
@@ -460,7 +467,7 @@ pub fn develop(develop_options: DevelopOptions, venv_dir: &Path) -> Result<()> {
460467
}
461468
};
462469

463-
install_dependencies(&build_context, &extras, &interpreter, &install_backend)?;
470+
install_dependencies(&build_context, &extras, &python, venv_dir, &install_backend)?;
464471

465472
let wheels = build_context.build_wheels()?;
466473
if !skip_install {

0 commit comments

Comments
 (0)