Skip to content

Commit

Permalink
Consider abi3 minor version when resolving Python interpreters
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jan 13, 2025
1 parent 1b29abf commit b24d01d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
34 changes: 32 additions & 2 deletions src/bridge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fmt::{Display, Formatter};

use crate::python_interpreter::{MINIMUM_PYPY_MINOR, MINIMUM_PYTHON_MINOR};

/// The name and version of the bindings crate
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Bindings {
Expand All @@ -11,7 +13,7 @@ pub struct Bindings {

impl Bindings {
/// Returns the minimum python minor version supported
pub fn minimal_python_minor_version(&self) -> usize {
fn minimal_python_minor_version(&self) -> usize {
use crate::python_interpreter::MINIMUM_PYTHON_MINOR;

match self.name.as_str() {
Expand All @@ -30,7 +32,7 @@ impl Bindings {
}

/// Returns the minimum PyPy minor version supported
pub fn minimal_pypy_minor_version(&self) -> usize {
fn minimal_pypy_minor_version(&self) -> usize {
use crate::python_interpreter::MINIMUM_PYPY_MINOR;

match self.name.as_str() {
Expand Down Expand Up @@ -121,6 +123,34 @@ impl BridgeModel {
matches!(self, BridgeModel::Bin(_))
}

/// Returns the minimum python minor version supported
pub fn minimal_python_minor_version(&self) -> usize {
match self {
BridgeModel::Bin(Some(bindings)) | BridgeModel::Bindings(bindings) => {
bindings.minimal_python_minor_version()
}
BridgeModel::BindingsAbi3 {
bindings,
minor: abi3_minor,
..
} => {
let bindings_minor = bindings.minimal_python_minor_version();
bindings_minor.max(*abi3_minor as usize)
}
BridgeModel::Bin(None) | BridgeModel::Cffi | BridgeModel::UniFfi => {
MINIMUM_PYTHON_MINOR
}
}
}

/// Returns the minimum PyPy minor version supported
pub fn minimal_pypy_minor_version(&self) -> usize {
match self.bindings() {
Some(bindings) => bindings.minimal_pypy_minor_version(),
None => MINIMUM_PYPY_MINOR,
}
}

/// free-threaded Python support
pub fn supports_free_threaded(&self) -> bool {
match self {
Expand Down
23 changes: 6 additions & 17 deletions src/python_interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,11 @@ impl PythonInterpreter {
requires_python: Option<&VersionSpecifiers>,
bridge: Option<&BridgeModel>,
) -> Vec<PythonInterpreter> {
let bindings = bridge.and_then(|bridge| bridge.bindings());
let min_python_minor = bindings
.map(|bindings| bindings.minimal_python_minor_version())
let min_python_minor = bridge
.map(|bridge| bridge.minimal_python_minor_version())
.unwrap_or(MINIMUM_PYTHON_MINOR);
let min_pypy_minor = bindings
.map(|bindings| bindings.minimal_pypy_minor_version())
let min_pypy_minor = bridge
.map(|bridge| bridge.minimal_pypy_minor_version())
.unwrap_or(MINIMUM_PYPY_MINOR);
let supports_free_threaded = bridge
.map(|bridge| bridge.supports_free_threaded())
Expand Down Expand Up @@ -794,18 +793,8 @@ impl PythonInterpreter {
bridge: &BridgeModel,
requires_python: Option<&VersionSpecifiers>,
) -> Result<Vec<PythonInterpreter>> {
let min_python_minor = match bridge {
BridgeModel::Bindings(bindings) | BridgeModel::Bin(Some(bindings)) => {
bindings.minimal_python_minor_version()
}
_ => MINIMUM_PYTHON_MINOR,
};
let min_pypy_minor = match bridge {
BridgeModel::Bindings(bindings) | BridgeModel::Bin(Some(bindings)) => {
bindings.minimal_pypy_minor_version()
}
_ => MINIMUM_PYPY_MINOR,
};
let min_python_minor = bridge.minimal_python_minor_version();
let min_pypy_minor = bridge.minimal_pypy_minor_version();
let executables = if target.is_windows() {
// TOFIX: add PyPy support to Windows
find_all_windows(target, min_python_minor, requires_python)?
Expand Down

0 comments on commit b24d01d

Please sign in to comment.