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

Add a --target option to maturin list-python command #957

Merged
merged 1 commit into from
Jun 8, 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 @@ -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

Expand Down
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ enum Opt {
},
#[clap(name = "list-python")]
/// Searches and lists the available python installations
ListPython,
ListPython {
#[clap(long)]
target: Option<String>,
},
#[clap(name = "develop")]
/// Installs the crate as module in the current virtualenv
///
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/python_interpreter/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ impl InterpreterConfig {
None
}

/// Lookup wellknown sysconfigs for a given target
pub fn lookup_target(target: &Target) -> Vec<Self> {
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<Self> {
let config_file = fs::File::open(config_file)?;
Expand Down
8 changes: 8 additions & 0 deletions src/python_interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,14 @@ impl PythonInterpreter {
}
}

/// Find all available python interpreters for a given target
pub fn find_by_target(target: &Target) -> Vec<PythonInterpreter> {
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(
Expand Down