Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix abi3 wheel build when no Python interpreters found #1072

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 55 additions & 0 deletions tests/common/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,58 @@ 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 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());

// Windows is a bit different so we exclude it from case 3 & 4

// Case 3: maturin build -i python2.7, errors because python2.7 is supported
#[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 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());
}