mirror of https://github.com/astral-sh/uv
Allow use of free-threaded variants in Python 3.14+ without explicit opt-in (#16142)
Closes https://github.com/astral-sh/uv/issues/15739 Closes #12445
This commit is contained in:
parent
7d63ef114a
commit
83f738074d
|
|
@ -1668,9 +1668,19 @@ fn is_windows_store_shim(_path: &Path) -> bool {
|
||||||
impl PythonVariant {
|
impl PythonVariant {
|
||||||
fn matches_interpreter(self, interpreter: &Interpreter) -> bool {
|
fn matches_interpreter(self, interpreter: &Interpreter) -> bool {
|
||||||
match self {
|
match self {
|
||||||
// TODO(zanieb): Right now, we allow debug interpreters to be selected by default for
|
Self::Default => {
|
||||||
// backwards compatibility, but we may want to change this in the future.
|
// TODO(zanieb): Right now, we allow debug interpreters to be selected by default for
|
||||||
Self::Default => !interpreter.gil_disabled(),
|
// backwards compatibility, but we may want to change this in the future.
|
||||||
|
if (interpreter.python_major(), interpreter.python_minor()) >= (3, 14) {
|
||||||
|
// For Python 3.14+, the free-threaded build is not considered experimental
|
||||||
|
// and can satisfy the default variant without opt-in
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
// In Python 3.13 and earlier, the free-threaded build is considered
|
||||||
|
// experimental and requires explicit opt-in
|
||||||
|
!interpreter.gil_disabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
Self::Debug => interpreter.debug_enabled(),
|
Self::Debug => interpreter.debug_enabled(),
|
||||||
Self::Freethreaded => interpreter.gil_disabled(),
|
Self::Freethreaded => interpreter.gil_disabled(),
|
||||||
Self::FreethreadedDebug => interpreter.gil_disabled() && interpreter.debug_enabled(),
|
Self::FreethreadedDebug => interpreter.gil_disabled() && interpreter.debug_enabled(),
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use assert_cmd::assert::OutputAssertExt;
|
||||||
use assert_fs::prelude::{FileTouch, PathChild};
|
use assert_fs::prelude::{FileTouch, PathChild};
|
||||||
use assert_fs::{fixture::FileWriteStr, prelude::PathCreateDir};
|
use assert_fs::{fixture::FileWriteStr, prelude::PathCreateDir};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
|
|
@ -1256,3 +1257,81 @@ fn python_find_path() {
|
||||||
error: No interpreter found at path `foobar`
|
error: No interpreter found at path `foobar`
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn python_find_freethreaded_313() {
|
||||||
|
let context: TestContext = TestContext::new_with_versions(&[])
|
||||||
|
.with_filtered_python_keys()
|
||||||
|
.with_filtered_python_sources()
|
||||||
|
.with_managed_python_dirs()
|
||||||
|
.with_python_download_cache()
|
||||||
|
.with_filtered_python_install_bin()
|
||||||
|
.with_filtered_python_names()
|
||||||
|
.with_filtered_exe_suffix();
|
||||||
|
|
||||||
|
context
|
||||||
|
.python_install()
|
||||||
|
.arg("--preview")
|
||||||
|
.arg("3.13t")
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
|
||||||
|
// Request Python 3.13 (without opt-in)
|
||||||
|
uv_snapshot!(context.filters(), context.python_find().arg("3.13"), @r"
|
||||||
|
success: false
|
||||||
|
exit_code: 2
|
||||||
|
----- stdout -----
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
error: No interpreter found for Python 3.13 in [PYTHON SOURCES]
|
||||||
|
");
|
||||||
|
|
||||||
|
// Request Python 3.13t (with explicit opt-in)
|
||||||
|
uv_snapshot!(context.filters(), context.python_find().arg("3.13t"), @r"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
[TEMP_DIR]/managed/cpython-3.13+freethreaded-[PLATFORM]/[INSTALL-BIN]/[PYTHON]
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn python_find_freethreaded_314() {
|
||||||
|
let context: TestContext = TestContext::new_with_versions(&[])
|
||||||
|
.with_filtered_python_keys()
|
||||||
|
.with_filtered_python_sources()
|
||||||
|
.with_managed_python_dirs()
|
||||||
|
.with_python_download_cache()
|
||||||
|
.with_filtered_python_install_bin()
|
||||||
|
.with_filtered_python_names()
|
||||||
|
.with_filtered_exe_suffix();
|
||||||
|
|
||||||
|
context
|
||||||
|
.python_install()
|
||||||
|
.arg("--preview")
|
||||||
|
.arg("3.14t")
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
|
||||||
|
// Request Python 3.14 (without opt-in)
|
||||||
|
uv_snapshot!(context.filters(), context.python_find().arg("3.14"), @r"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
[TEMP_DIR]/managed/cpython-3.14+freethreaded-[PLATFORM]/[INSTALL-BIN]/[PYTHON]
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
");
|
||||||
|
|
||||||
|
// Request Python 3.14t (with explicit opt-in)
|
||||||
|
uv_snapshot!(context.filters(), context.python_find().arg("3.14t"), @r"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
[TEMP_DIR]/managed/cpython-3.14+freethreaded-[PLATFORM]/[INSTALL-BIN]/[PYTHON]
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue