Skip to content

Commit

Permalink
Add a --target option to maturin list-python command
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jun 8, 2022
1 parent 494a07b commit 965585e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
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 965585e

Please sign in to comment.