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

Consider abi3 minor version when resolving Python interpreters #2437

Merged
merged 1 commit into from
Jan 13, 2025
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
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
Loading