diff --git a/Changelog.md b/Changelog.md index dfc36d56f..d17efe700 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fix incompatibility with cibuildwheel for 32-bit Windows in [#951](https://github.com/PyO3/maturin/pull/951) * Don't require `pip` error messages to be utf-8 encoding in [#953](https://github.com/PyO3/maturin/pull/953) * Compare minimum python version requirement between `requires-python` and bindings crate in [#954](https://github.com/PyO3/maturin/pull/954) +* Add a `--target` option to `maturin list-python` command in [#957](https://github.com/PyO3/maturin/pull/957) ## [0.12.19] - 2022-06-05 diff --git a/src/main.rs b/src/main.rs index 5f0eb6264..427e82795 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,7 +59,10 @@ enum Opt { }, #[clap(name = "list-python")] /// Searches and lists the available python installations - ListPython, + ListPython { + #[clap(long)] + target: Option, + }, #[clap(name = "develop")] /// Installs the crate as module in the current virtualenv /// @@ -361,10 +364,15 @@ fn run() -> Result<()> { upload_ui(&items, &publish)? } - Opt::ListPython => { - let target = Target::from_target_triple(None)?; - // We don't know the targeted bindings yet, so we use the most lenient - let found = PythonInterpreter::find_all(&target, &BridgeModel::Cffi, None)?; + Opt::ListPython { target } => { + let found = if target.is_some() { + let target = Target::from_target_triple(target)?; + PythonInterpreter::find_by_target(&target) + } else { + let target = Target::from_target_triple(None)?; + // We don't know the targeted bindings yet, so we use the most lenient + PythonInterpreter::find_all(&target, &BridgeModel::Cffi, None)? + }; println!("🐍 {} python interpreter found:", found.len()); for interpreter in found { println!(" - {}", interpreter); diff --git a/src/python_interpreter/config.rs b/src/python_interpreter/config.rs index 8c9051369..3c21aea1a 100644 --- a/src/python_interpreter/config.rs +++ b/src/python_interpreter/config.rs @@ -85,6 +85,16 @@ impl InterpreterConfig { None } + /// Lookup wellknown sysconfigs for a given target + pub fn lookup_target(target: &Target) -> Vec { + if let Some(os_sysconfigs) = WELLKNOWN_SYSCONFIG.get(&target.target_os()) { + if let Some(sysconfigs) = os_sysconfigs.get(&target.target_arch()).cloned() { + return sysconfigs; + } + } + Vec::new() + } + /// Construct a new InterpreterConfig from a pyo3 config file pub fn from_pyo3_config(config_file: &Path, target: &Target) -> Result { let config_file = fs::File::open(config_file)?; diff --git a/src/python_interpreter/mod.rs b/src/python_interpreter/mod.rs index e772a9fa1..91f3de7a8 100644 --- a/src/python_interpreter/mod.rs +++ b/src/python_interpreter/mod.rs @@ -619,6 +619,14 @@ impl PythonInterpreter { } } + /// Find all available python interpreters for a given target + pub fn find_by_target(target: &Target) -> Vec { + InterpreterConfig::lookup_target(target) + .into_iter() + .map(Self::from_config) + .collect() + } + /// Tries to find all installed python versions using the heuristic for the /// given platform pub fn find_all(