mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-03 18:38:21 +00:00
Allow fallback to Python download on non-critical discovery errors (#10908)
Closes https://github.com/astral-sh/uv/issues/10898 In #10716, I broke fallback to downloading Python versions by throwing a different error kind.
This commit is contained in:
parent
2a0fa8a8ee
commit
cbf6d5af9e
2 changed files with 45 additions and 37 deletions
|
@ -92,36 +92,48 @@ impl PythonInstallation {
|
|||
let request = request.unwrap_or(&PythonRequest::Default);
|
||||
|
||||
// Search for the installation
|
||||
match Self::find(request, environments, preference, cache) {
|
||||
Ok(venv) => Ok(venv),
|
||||
// If missing and allowed, perform a fetch
|
||||
Err(Error::MissingPython(err))
|
||||
if preference.allows_managed()
|
||||
&& python_downloads.is_automatic()
|
||||
&& client_builder.connectivity.is_online() =>
|
||||
{
|
||||
if let Some(request) = PythonDownloadRequest::from_request(request) {
|
||||
debug!("Requested Python not found, checking for available download...");
|
||||
match Self::fetch(
|
||||
request.fill()?,
|
||||
client_builder,
|
||||
cache,
|
||||
reporter,
|
||||
python_install_mirror,
|
||||
pypy_install_mirror,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(installation) => Ok(installation),
|
||||
Err(Error::Download(downloads::Error::NoDownloadFound(_))) => {
|
||||
Err(Error::MissingPython(err))
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
} else {
|
||||
Err(Error::MissingPython(err))
|
||||
}
|
||||
}
|
||||
let err = match Self::find(request, environments, preference, cache) {
|
||||
Ok(installation) => return Ok(installation),
|
||||
Err(err) => err,
|
||||
};
|
||||
|
||||
let downloads_enabled = preference.allows_managed()
|
||||
&& python_downloads.is_automatic()
|
||||
&& client_builder.connectivity.is_online();
|
||||
|
||||
if !downloads_enabled {
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
match err {
|
||||
// If Python is missing, we should attempt a download
|
||||
Error::MissingPython(_) => {}
|
||||
// If we raised a non-critical error, we should attempt a download
|
||||
Error::Discovery(ref err) if !err.is_critical() => {}
|
||||
// Otherwise, this is fatal
|
||||
_ => return Err(err),
|
||||
}
|
||||
|
||||
// If we can't convert the request to a download, throw the original error
|
||||
let Some(request) = PythonDownloadRequest::from_request(request) else {
|
||||
return Err(err);
|
||||
};
|
||||
|
||||
debug!("Requested Python not found, checking for available download...");
|
||||
match Self::fetch(
|
||||
request.fill()?,
|
||||
client_builder,
|
||||
cache,
|
||||
reporter,
|
||||
python_install_mirror,
|
||||
pypy_install_mirror,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(installation) => Ok(installation),
|
||||
// Throw the original error if we couldn't find a download
|
||||
Err(Error::Download(downloads::Error::NoDownloadFound(_))) => Err(err),
|
||||
// But if the download failed, throw that error
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue