From c840a769cdd4968e5e513c8e5fa3a076ce89a8c2 Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 19 May 2023 21:24:26 +0800 Subject: [PATCH] Fix `cargo test` failures in devcontainer (#1618) --- src/build_options.rs | 33 ++++++++++++++++++++++++--------- tests/common/errors.rs | 2 -- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/build_options.rs b/src/build_options.rs index f81c62e56..c00feb7c2 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -1057,33 +1057,45 @@ fn find_interpreter( target: &Target, requires_python: Option<&VersionSpecifiers>, ) -> Result> { - 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::>() + .join(", "); + bail!( + "Couldn't find any python interpreters from {}.", + interps_str + ); } } - Ok(interpreters) + Ok(found_interpreters) } /// Find python interpreters in the host machine @@ -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")?; diff --git a/tests/common/errors.rs b/tests/common/errors.rs index 4d3b38c99..e27945bf2 100644 --- a/tests/common/errors.rs +++ b/tests/common/errors.rs @@ -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", ]; @@ -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",