diff --git a/Changelog.md b/Changelog.md index b2e40a1d9..7835047fb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] * **Breaking Change**: Drop support for python 3.6, which is end of life +* Fix Windows Store install detection in [#949](https://github.com/PyO3/maturin/pull/949) +* Filter Python interpreters by target pointer width on Windows in [#950](https://github.com/PyO3/maturin/pull/950) ## [0.12.18] - 2022-05-29 diff --git a/src/python_interpreter/mod.rs b/src/python_interpreter/mod.rs index bac3f6265..0bd0916a1 100644 --- a/src/python_interpreter/mod.rs +++ b/src/python_interpreter/mod.rs @@ -182,51 +182,18 @@ fn find_all_windows(target: &Target, min_python_minor: usize) -> Result python_info, - Err(err) => { - if err.kind() == io::ErrorKind::NotFound { - // This conda env doesn't have python installed - continue; - } else { - bail!( - "Error getting Python version info from conda env at {}", - path - ); - } - } - }; - - let version_info = str::from_utf8(&python_info.stdout).unwrap(); - let expr = Regex::new(r"(\d).(\d).(\d+)").unwrap(); - if let Some(capture) = expr.captures(version_info) { - let major = capture.get(1).unwrap().as_str().parse::().unwrap(); - let minor = capture.get(2).unwrap().as_str().parse::().unwrap(); - if !versions_found.contains(&(major, minor)) { - let pointer_width = if version_info.contains("64 bit (AMD64)") { - 64_usize - } else { - 32_usize - }; - - if windows_interpreter_no_build( - major, - minor, - target.pointer_width(), - pointer_width, - min_python_minor, - ) { - continue; - } - - interpreter.push(String::from(executable.to_str().unwrap())); - versions_found.insert((major, minor)); + if let Some(python_info) = windows_python_info(&executable)? { + if windows_interpreter_no_build( + python_info.major, + python_info.minor, + target.pointer_width(), + python_info.pointer_width.unwrap(), + min_python_minor, + ) { + continue; } + interpreter.push(String::from(executable.to_str().unwrap())); + versions_found.insert((python_info.major, python_info.minor)); } } } @@ -234,8 +201,20 @@ fn find_all_windows(target: &Target, min_python_minor: usize) -> Result Result Result> { + let python_info = Command::new(&executable) + .arg("-c") + .arg("import sys; print(sys.version)") + .output(); + + let python_info = match python_info { + Ok(python_info) => python_info, + Err(err) => { + if err.kind() == io::ErrorKind::NotFound { + // python executable not found + return Ok(None); + } else { + bail!( + "Error getting Python version info from {}", + executable.display() + ); + } + } + }; + + let version_info = str::from_utf8(&python_info.stdout).unwrap(); + let expr = Regex::new(r"(\d).(\d).(\d+)").unwrap(); + if let Some(capture) = expr.captures(version_info) { + let major = capture.get(1).unwrap().as_str().parse::().unwrap(); + let minor = capture.get(2).unwrap().as_str().parse::().unwrap(); + let pointer_width = if version_info.contains("64 bit (AMD64)") { + 64 + } else { + 32 + }; + Ok(Some(InterpreterConfig { + major, + minor, + interpreter_kind: InterpreterKind::CPython, + abiflags: String::new(), + ext_suffix: String::new(), + abi_tag: None, + pointer_width: Some(pointer_width), + })) + } else { + Ok(None) + } +} + #[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize)] #[serde(rename_all = "lowercase")] pub enum InterpreterKind { @@ -512,7 +536,7 @@ impl PythonInterpreter { }; // Try py -x.y on Windows let output = Command::new("py") - .arg(format!("-{}", ver)) + .arg(format!("-{}-{}", ver, target.pointer_width())) .args(&["-c", GET_INTERPRETER_METADATA]) .output(); match output {