Skip to content

Commit

Permalink
Fix abi3 wheel build when no Python interpreters found
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Aug 31, 2022
1 parent 3dbbe05 commit 13b9b3e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 10 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Allow user to override default Emscripten settings in [#1059](https://github.com/PyO3/maturin/pull/1059)
* Enable `--crate-type cdylib` on Rust 1.64.0 in [#1060](https://github.com/PyO3/maturin/pull/1060)
* Update MSRV to 1.59.0 in [#1071](https://github.com/PyO3/maturin/pull/1071)
* Fix abi3 wheel build when no Python interpreters found in [#1072](https://github.com/PyO3/maturin/pull/1072)

## [0.13.2] - 2022-08-14

Expand Down
30 changes: 20 additions & 10 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,28 @@ impl BuildOptions {
bail!("Failed to find a python interpreter");
}
} else {
let interpreters = find_interpreter_in_host(
let found_interpreters = find_interpreter_in_host(
bridge,
interpreter,
target,
Some(*minor as usize),
)
.unwrap_or_else(|_| {
find_interpreter_in_sysconfig(interpreter, target, Some(*minor as usize))
.unwrap_or_default()
});
.or_else(|err| {
let interps = find_interpreter_in_sysconfig(
interpreter,
target,
Some(*minor as usize),
)
.unwrap_or_default();
if interps.is_empty() && !self.interpreter.is_empty() {
// Print error when user supplied `--interpreter` option
Err(err)
} else {
Ok(interps)
}
})?;
println!("🐍 Not using a specific python interpreter");
if interpreter.is_empty() {
if self.interpreter.is_empty() {
// Fake one to make `BuildContext::build_wheels` happy for abi3 when no cpython/pypy found on host
// The python interpreter config doesn't matter, as it's not used for anything
Ok(vec![PythonInterpreter {
Expand All @@ -432,9 +442,9 @@ impl BuildOptions {
runnable: false,
}])
} else if target.cross_compiling() {
let mut interps = Vec::with_capacity(interpreters.len());
let mut interps = Vec::with_capacity(found_interpreters.len());
let mut pypys = Vec::new();
for interp in interpreters {
for interp in found_interpreters {
if interp.interpreter_kind.is_pypy() {
pypys.push(PathBuf::from(format!(
"pypy{}.{}",
Expand All @@ -458,10 +468,10 @@ impl BuildOptions {
}
Ok(interps)
} else {
if interpreters.is_empty() {
if found_interpreters.is_empty() {
bail!("Failed to find any python interpreter");
}
Ok(interpreters)
Ok(found_interpreters)
}
}
}
Expand Down
54 changes: 54 additions & 0 deletions tests/common/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,57 @@ pub fn test_source_distribution(
);
Ok(())
}

pub fn abi3_python_interpreter_args() -> Result<()> {
// Case 1: maturin build without `-i`, should work
let options = BuildOptions::try_parse_from(vec![
"build",
"--manifest-path",
"test-crates/pyo3-pure/Cargo.toml",
"--quiet",
])?;
let result = options.into_build_context(false, cfg!(feature = "faster-tests"), false);
assert!(result.is_ok());

// Case 2: maturin build -i python2.7, errors because python2.7 is supported
// Windows is a bit different so we exclude it from this case
#[cfg(not(windows))]
{
let options = BuildOptions::try_parse_from(vec![
"build",
"--manifest-path",
"test-crates/pyo3-pure/Cargo.toml",
"--quiet",
"-i",
"python2.7",
])?;
let result = options.into_build_context(false, cfg!(feature = "faster-tests"), false);
assert!(result.is_err());
}

// Case 3: maturin build -i python3.10, should work because python3.10 is in bundled sysconfigs
let options = BuildOptions::try_parse_from(vec![
"build",
"--manifest-path",
"test-crates/pyo3-pure/Cargo.toml",
"--quiet",
"-i",
"python3.10",
])?;
let result = options.into_build_context(false, cfg!(feature = "faster-tests"), false);
assert!(result.is_ok());

// Case 4: maturin build -i python-does-not-exists, errors because python executable is not found
let options = BuildOptions::try_parse_from(vec![
"build",
"--manifest-path",
"test-crates/pyo3-pure/Cargo.toml",
"--quiet",
"-i",
"python-does-not-exists",
])?;
let result = options.into_build_context(false, cfg!(feature = "faster-tests"), false);
assert!(result.is_err());

Ok(())
}
5 changes: 5 additions & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,8 @@ fn workspace_with_path_dep_sdist() {
"workspace_with_path_dep_sdist",
))
}

#[test]
fn abi3_python_interpreter_args() {
handle_result(other::abi3_python_interpreter_args());
}

0 comments on commit 13b9b3e

Please sign in to comment.