From f862457f0544ca443ff7360904f6e4ff96bfb2f7 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 9 Jul 2024 01:29:55 -0400 Subject: [PATCH] Avoid debug error for `uv run` with unknown Python version (#4913) ## Summary Closes https://github.com/astral-sh/uv/issues/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 ``` --- crates/uv-python/src/installation.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/uv-python/src/installation.rs b/crates/uv-python/src/installation.rs index fc0916a48..92995a6ab 100644 --- a/crates/uv-python/src/installation.rs +++ b/crates/uv-python/src/installation.rs @@ -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)] @@ -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),