Skip to content

Commit

Permalink
Fix cargo test failures in devcontainer (#1618)
Browse files Browse the repository at this point in the history
  • Loading branch information
messense authored May 19, 2023
1 parent cd29014 commit c840a76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 24 additions & 9 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,33 +1057,45 @@ fn find_interpreter(
target: &Target,
requires_python: Option<&VersionSpecifiers>,
) -> Result<Vec<PythonInterpreter>> {
let mut interpreters = Vec::new();
let mut found_interpreters = Vec::new();
if !interpreter.is_empty() {
let mut missing = Vec::new();
for interp in interpreter {
match PythonInterpreter::check_executable(interp.clone(), target, bridge) {
Ok(Some(interp)) => interpreters.push(interp),
Ok(Some(interp)) => found_interpreters.push(interp),
_ => missing.push(interp.clone()),
}
}
if !missing.is_empty() {
let sysconfig_interps =
find_interpreter_in_sysconfig(&missing, target, requires_python)?;
interpreters.extend(sysconfig_interps);
found_interpreters.extend(sysconfig_interps);
}
} else {
interpreters = PythonInterpreter::find_all(target, bridge, requires_python)
found_interpreters = PythonInterpreter::find_all(target, bridge, requires_python)
.context("Finding python interpreters failed")?;
};

if interpreters.is_empty() {
if let Some(requires_python) = requires_python {
bail!("Couldn't find any python interpreters with version {}. Please specify at least one with -i", requires_python);
if found_interpreters.is_empty() {
if interpreter.is_empty() {
if let Some(requires_python) = requires_python {
bail!("Couldn't find any python interpreters with version {}. Please specify at least one with -i", requires_python);
} else {
bail!("Couldn't find any python interpreters. Please specify at least one with -i");
}
} else {
bail!("Couldn't find any python interpreters. Please specify at least one with -i");
let interps_str = interpreter
.iter()
.map(|path| format!("'{}'", path.display()))
.collect::<Vec<_>>()
.join(", ");
bail!(
"Couldn't find any python interpreters from {}.",
interps_str
);
}
}
Ok(interpreters)
Ok(found_interpreters)
}

/// Find python interpreters in the host machine
Expand Down Expand Up @@ -1141,6 +1153,9 @@ fn find_interpreter_in_sysconfig(
} else {
bail!("Unsupported Python interpreter: {}", python);
};
if python_ver.is_empty() {
continue;
}
let (ver_major, ver_minor) = python_ver
.split_once('.')
.context("Invalid python interpreter version")?;
Expand Down
2 changes: 0 additions & 2 deletions tests/common/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub fn pyo3_no_extension_module() -> Result<()> {
"--quiet",
"--target-dir",
"test-crates/targets/pyo3_no_extension_module",
"-i=python",
"--out",
"test-crates/targets/pyo3_no_extension_module",
];
Expand Down Expand Up @@ -107,7 +106,6 @@ pub fn invalid_manylinux_does_not_panic() -> Result<()> {
"build",
"-m",
"test-crates/pyo3-mixed/Cargo.toml",
"-i=python",
"--compatibility",
"manylinux_2_99",
"--target-dir",
Expand Down

0 comments on commit c840a76

Please sign in to comment.