Skip to content

Commit

Permalink
Merge pull request #957 from messense/list-python
Browse files Browse the repository at this point in the history
Add a `--target` option to `maturin list-python` command
  • Loading branch information
messense authored Jun 8, 2022
2 parents 494a07b + 8f0e218 commit 9042c79
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
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

0 comments on commit 9042c79

Please sign in to comment.