Skip to content

Commit

Permalink
Locate python interpreter python after creating venv
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Nov 26, 2024
1 parent 6e61116 commit e36b065
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions tests/common/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ pub fn test_integration(
let shed = format!("test-crates/wheels/{unique_name}");
let target_dir = format!("test-crates/targets/{unique_name}");
let python_interp = test_python_path();
let mut cli = vec![
"build",
"--quiet",
"--manifest-path",
&package_string,
"--target-dir",
&target_dir,
"--out",
&shed,
let mut cli: Vec<std::ffi::OsString> = vec![
"build".into(),
"--quiet".into(),
"--manifest-path".into(),
package_string.into(),
"--target-dir".into(),
target_dir.into(),
"--out".into(),
shed.into(),
];

if let Some(ref bindings) = bindings {
cli.push("--bindings");
cli.push(bindings);
cli.push("--bindings".into());
cli.push(bindings.into());
}

if let Some(target) = target {
cli.push("--target");
cli.push(target)
cli.push("--target".into());
cli.push(target.into())
}

#[cfg(feature = "zig")]
Expand All @@ -65,11 +65,11 @@ pub fn test_integration(
let zig_found = false;

let test_zig = if zig && (env::var("GITHUB_ACTIONS").is_ok() || zig_found) {
cli.push("--zig");
cli.push("--zig".into());
true
} else {
cli.push("--compatibility");
cli.push("linux");
cli.push("--compatibility".into());
cli.push("linux".into());
false
};

Expand All @@ -80,21 +80,21 @@ pub fn test_integration(
.join("venvs");
let cffi_provider = "cffi-provider";
let cffi_venv = venvs_dir.join(cffi_provider);
let target_triple = Target::from_target_triple(None)?;
let python = target_triple.get_venv_python(&cffi_venv);

if let Some(interp) = python_interp.as_ref() {
cli.push("--interpreter");
cli.push(interp);
cli.push("--interpreter".into());
cli.push(interp.into());
} else {
// Install cffi in a separate environment

// All tests try to use this venv at the same time, so we need to make sure only one
// modifies it at a time and that during that time, no other test reads it.
let file = File::create(venvs_dir.join("cffi-provider.lock"))?;
file.lock_exclusive()?;
if !python.is_file() {
let python = if !cffi_venv.is_dir() {
create_named_virtualenv(cffi_provider, python_interp.clone().map(PathBuf::from))?;
let target_triple = Target::from_target_triple(None)?;
let python = target_triple.get_venv_python(&cffi_venv);
assert!(python.is_file(), "cffi venv not created correctly");
let pip_install_cffi = [
"-m",
Expand All @@ -118,14 +118,14 @@ pub fn test_integration(
stderr
);
}
}
file.unlock()?;
cli.push("--interpreter");
cli.push(
python
.to_str()
.context("non-utf8 python interpreter path")?,
);
} else {
let target_triple = Target::from_target_triple(None)?;
target_triple.get_venv_python(&cffi_venv)
};
file.unlock()?;
cli.push("--interpreter".into());
cli.push(python.as_os_str().to_owned());
}

let options: BuildOptions = BuildOptions::try_parse_from(cli)?;
Expand Down Expand Up @@ -239,20 +239,20 @@ pub fn test_integration_conda(package: impl AsRef<Path>, bindings: Option<String
}

// The first argument is ignored by clap
let mut cli = vec![
"build",
"--manifest-path",
&package_string,
"--quiet",
"--interpreter",
let mut cli: Vec<std::ffi::OsString> = vec![
"build".into(),
"--manifest-path".into(),
package_string.into(),
"--quiet".into(),
"--interpreter".into(),
];
for interp in &interpreters {
cli.push(interp.to_str().unwrap());
cli.push(interp.to_str().unwrap().into());
}

if let Some(ref bindings) = bindings {
cli.push("--bindings");
cli.push(bindings);
cli.push("--bindings".into());
cli.push(bindings.into());
}

let options = BuildOptions::try_parse_from(cli)?;
Expand Down

0 comments on commit e36b065

Please sign in to comment.