From e65db943ff807db12171af0c2277051e1ddaeafe Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 16 Apr 2024 20:29:51 +0800 Subject: [PATCH] Install cffi and uv on demand in `test_develop` (#2043) --- tests/common/develop.rs | 40 +++++++++++++++++++++------------------- tests/common/mod.rs | 1 + 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/tests/common/develop.rs b/tests/common/develop.rs index edf44ad4..105537d3 100644 --- a/tests/common/develop.rs +++ b/tests/common/develop.rs @@ -28,32 +28,34 @@ pub fn test_develop( // Ensure the test doesn't wrongly pass check_installed(package, &python).unwrap_err(); - let mut cmd = Command::new(&python); - cmd.args([ - "-m", - "pip", - "install", - "--disable-pip-version-check", - "cffi", - ]); + let uv = matches!(test_backend, TestInstallBackend::Uv); + let mut pip_packages = Vec::new(); + if unique_name.contains("cffi") { + pip_packages.push("cffi"); + } if cfg!(any( target_os = "linux", target_os = "macos", target_os = "windows" - )) { - cmd.arg("uv"); + )) && uv + { + pip_packages.push("uv"); } - let output = cmd.output()?; - if !output.status.success() { - panic!( - "Failed to install cffi: {}\n---stdout:\n{}---stderr:\n{}", - output.status, - str::from_utf8(&output.stdout)?, - str::from_utf8(&output.stderr)? - ); + if !pip_packages.is_empty() { + let mut cmd = Command::new(&python); + cmd.args(["-m", "pip", "install", "--disable-pip-version-check"]) + .args(pip_packages); + let output = cmd.output()?; + if !output.status.success() { + panic!( + "Failed to install cffi: {}\n---stdout:\n{}---stderr:\n{}", + output.status, + str::from_utf8(&output.stdout)?, + str::from_utf8(&output.stderr)? + ); + } } - let uv = matches!(test_backend, TestInstallBackend::Uv); let manifest_file = package.join("Cargo.toml"); let develop_options = DevelopOptions { bindings, diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 7c238f07..28561cf2 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -12,6 +12,7 @@ pub mod errors; pub mod integration; pub mod other; +#[derive(Clone, Copy, PartialEq, Eq)] pub enum TestInstallBackend { Pip, Uv,