Skip to content

Commit

Permalink
Avoid debug error for uv run with unknown Python version (#4913)
Browse files Browse the repository at this point in the history
## Summary

Closes #4848.

## Test Plan

```
> cargo run -- run -vv --preview --isolated --python 3.12.4 python -V
error: No interpreter found for Python 3.12.4 in virtual environments or managed installations or system path
```
  • Loading branch information
charliermarsh authored Jul 9, 2024
1 parent ed4234d commit f862457
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/uv-python/src/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use crate::downloads::{DownloadResult, ManagedPythonDownload, PythonDownloadRequ
use crate::implementation::LenientImplementationName;
use crate::managed::{ManagedPythonInstallation, ManagedPythonInstallations};
use crate::platform::{Arch, Libc, Os};
use crate::{Error, Interpreter, PythonFetch, PythonPreference, PythonSource, PythonVersion};
use crate::{
downloads, Error, Interpreter, PythonFetch, PythonPreference, PythonSource, PythonVersion,
};

/// A Python interpreter and accompanying tools.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -97,16 +99,22 @@ impl PythonInstallation {
match Self::find(&request, environments, preference, cache) {
Ok(venv) => Ok(venv),
// If missing and allowed, perform a fetch
err @ Err(Error::MissingPython(_))
Err(Error::MissingPython(err))
if preference.allows_managed()
&& python_fetch.is_automatic()
&& client_builder.connectivity.is_online() =>
{
if let Some(request) = PythonDownloadRequest::try_from_request(&request) {
debug!("Requested Python not found, checking for available download...");
Self::fetch(request.fill(), client_builder, cache, reporter).await
match Self::fetch(request.fill(), client_builder, cache, reporter).await {
Ok(installation) => Ok(installation),
Err(Error::Download(downloads::Error::NoDownloadFound(_))) => {
Err(Error::MissingPython(err))
}
Err(err) => Err(err),
}
} else {
err
Err(Error::MissingPython(err))
}
}
Err(err) => Err(err),
Expand Down

0 comments on commit f862457

Please sign in to comment.