Skip to content

Commit

Permalink
Do not use free-threaded interpreters without a free-threaded request
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Oct 14, 2024
1 parent 01c44af commit d2064a4
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions crates/uv-python/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,14 @@ fn is_windows_store_shim(_path: &Path) -> bool {
false
}

impl PythonVariant {
fn matches_interpreter(&self, interpreter: &Interpreter) -> bool {
match self {
PythonVariant::Default => !interpreter.gil_disabled(),
PythonVariant::Freethreaded => interpreter.gil_disabled(),
}
}
}
impl PythonRequest {
/// Create a request from a string.
///
Expand Down Expand Up @@ -1798,27 +1806,30 @@ impl VersionRequest {

/// Check if a interpreter matches the requested Python version.
pub(crate) fn matches_interpreter(&self, interpreter: &Interpreter) -> bool {
if self.is_freethreaded() && !interpreter.gil_disabled() {
return false;
}
match self {
Self::Any | Self::Default => true,
Self::Major(major, _) => interpreter.python_major() == *major,
Self::MajorMinor(major, minor, _) => {
Self::Any => true,
// Do not use free-threaded interpreters by default
Self::Default => PythonVariant::Default.matches_interpreter(interpreter),
Self::Major(major, variant) => {
interpreter.python_major() == *major && variant.matches_interpreter(interpreter)
}
Self::MajorMinor(major, minor, variant) => {
(interpreter.python_major(), interpreter.python_minor()) == (*major, *minor)
&& variant.matches_interpreter(interpreter)
}
Self::MajorMinorPatch(major, minor, patch, _) => {
Self::MajorMinorPatch(major, minor, patch, variant) => {
(
interpreter.python_major(),
interpreter.python_minor(),
interpreter.python_patch(),
) == (*major, *minor, *patch)
&& variant.matches_interpreter(interpreter)
}
Self::Range(specifiers, _) => {
Self::Range(specifiers, variant) => {
let version = interpreter.python_version().only_release();
specifiers.contains(&version)
specifiers.contains(&version) && variant.matches_interpreter(interpreter)
}
Self::MajorMinorPrerelease(major, minor, prerelease, _) => {
Self::MajorMinorPrerelease(major, minor, prerelease, variant) => {
let version = interpreter.python_version();
let Some(interpreter_prerelease) = version.pre() else {
return false;
Expand All @@ -1828,6 +1839,7 @@ impl VersionRequest {
interpreter.python_minor(),
interpreter_prerelease,
) == (*major, *minor, *prerelease)
&& variant.matches_interpreter(interpreter)
}
}
}
Expand Down

0 comments on commit d2064a4

Please sign in to comment.