Skip to content

Commit

Permalink
Merge pull request #943 from messense/windows-py-c
Browse files Browse the repository at this point in the history
Fallback to `py -X.Y` when `pythonX.Y` cannot be found on Windows
  • Loading branch information
messense authored May 27, 2022
2 parents fd75248 + 7121100 commit 890494c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add Python 3.11 sysconfig for arm64 Windows in [#936](https://github.com/PyO3/maturin/pull/936)
* Add network proxy support to upload command in [#939](https://github.com/PyO3/maturin/pull/939)
* Fix python interpreter detection on arm64 Windows in [#940](https://github.com/PyO3/maturin/pull/940)
* Fallback to `py -X.Y` when `pythonX.Y` cannot be found on Windows in [#943](https://github.com/PyO3/maturin/pull/943)

## [0.12.17] - 2022-05-18

Expand Down
1 change: 1 addition & 0 deletions src/python_interpreter/get_interpreter_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")

metadata = {
"executable": sys.executable or None,
"major": sys.version_info.major,
"minor": sys.version_info.minor,
"abiflags": sysconfig.get_config_var("ABIFLAGS"),
Expand Down
25 changes: 24 additions & 1 deletion src/python_interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl FromStr for InterpreterKind {
/// The output format of [GET_INTERPRETER_METADATA]
#[derive(Deserialize)]
struct IntepreterMetadataMessage {
executable: Option<String>,
major: usize,
minor: usize,
abiflags: Option<String>,
Expand Down Expand Up @@ -488,6 +489,25 @@ impl PythonInterpreter {
}
Err(err) => {
if err.kind() == io::ErrorKind::NotFound {
#[cfg(windows)]
{
if let Some(python) = executable.as_ref().to_str() {
let ver = if python.starts_with("python") {
python.strip_prefix("python").unwrap_or(python)
} else {
python
};
// Try py -x.y on Windows
let output = Command::new("py")
.arg(format!("-{}", ver))
.args(&["-c", GET_INTERPRETER_METADATA])
.output()?;
output
} else {
return Ok(None);
}
}
#[cfg(not(windows))]
return Ok(None);
} else {
return Err(err).context(err_msg);
Expand Down Expand Up @@ -540,7 +560,10 @@ impl PythonInterpreter {
abi_tag: message.abi_tag,
pointer_width: None,
},
executable: executable.as_ref().to_path_buf(),
executable: message
.executable
.map(PathBuf::from)
.unwrap_or_else(|| executable.as_ref().to_path_buf()),
platform,
runnable: true,
}))
Expand Down

0 comments on commit 890494c

Please sign in to comment.