Ignore pre-release versions in uv init --script (#15747)

## Summary

Ignore managed pre-release versions of Python for purposes of creating a
`requires-python` constraint when running `uv init --script`. This makes
the behavior consistent with `uv init` for normal projects.

## Test Plan

Added a regression test that makes sure that the constraint is
`requires-python = ">=3.13"`, even though a pre-release version of 3.14
is installed.
This commit is contained in:
David Peter
2025-09-10 21:35:29 +02:00
committed by GitHub
parent ab2880f389
commit 0d174b79e2
7 changed files with 72 additions and 13 deletions
+16 -2
View File
@@ -726,7 +726,7 @@ fn python_interpreters<'a>(
cache: &'a Cache,
preview: Preview,
) -> impl Iterator<Item = Result<(PythonSource, Interpreter), Error>> + 'a {
python_interpreters_from_executables(
let interpreters = python_interpreters_from_executables(
// Perform filtering on the discovered executables based on their source. This avoids
// unnecessary interpreter queries, which are generally expensive. We'll filter again
// with `interpreter_satisfies_environment_preference` after querying.
@@ -760,7 +760,21 @@ fn python_interpreters<'a>(
})
.filter_ok(move |(source, interpreter)| {
satisfies_python_preference(*source, interpreter, preference)
})
});
if std::env::var(uv_static::EnvVars::UV_INTERNAL__TEST_PYTHON_MANAGED).is_ok() {
Either::Left(interpreters.map_ok(|(source, interpreter)| {
// In test mode, change the source to `Managed` if a version was marked as such via
// `TestContext::with_versions_as_managed`.
if interpreter.is_managed() {
(PythonSource::Managed, interpreter)
} else {
(source, interpreter)
}
}))
} else {
Either::Right(interpreters)
}
}
/// Lazily convert Python executables into interpreters.