Prefer stable releases over pre-releases in uv python install (#12194)

e.g., `uv python install 3` should not install the 3.14 alpha

Closes #12184
This commit is contained in:
Zanie Blue 2025-04-21 16:16:07 -05:00 committed by GitHub
parent c55dd0f295
commit 9484e3663c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 116 additions and 9 deletions

View file

@ -2294,9 +2294,9 @@ impl VersionRequest {
match self {
Self::Default => false,
Self::Any => true,
Self::Major(..) => true,
Self::MajorMinor(..) => true,
Self::MajorMinorPatch(..) => true,
Self::Major(..) => false,
Self::MajorMinor(..) => false,
Self::MajorMinorPatch(..) => false,
Self::MajorMinorPrerelease(..) => true,
Self::Range(specifiers, _) => specifiers.iter().any(VersionSpecifier::any_prerelease),
}

View file

@ -485,13 +485,28 @@ pub enum DownloadResult {
impl ManagedPythonDownload {
/// Return the first [`ManagedPythonDownload`] matching a request, if any.
///
/// If there is no stable version matching the request, a compatible pre-release version will
/// be searched for — even if a pre-release was not explicitly requested.
pub fn from_request(
request: &PythonDownloadRequest,
) -> Result<&'static ManagedPythonDownload, Error> {
request
.iter_downloads()?
.next()
.ok_or(Error::NoDownloadFound(request.clone()))
if let Some(download) = request.iter_downloads()?.next() {
return Ok(download);
}
if !request.allows_prereleases() {
if let Some(download) = request
.clone()
.with_prereleases(true)
.iter_downloads()?
.next()
{
return Ok(download);
}
}
Err(Error::NoDownloadFound(request.clone()))
}
/// Iterate over all [`ManagedPythonDownload`]s.