From 2be93c0b2caf74c7e2009d503cf03fad2eaec3d8 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 5 Jun 2024 08:26:56 -0400 Subject: [PATCH] Display selected interpreter sources during not selected error (#4026) This should help us narrow down the weird error in https://github.com/astral-sh/uv/issues/4023 --- crates/uv-interpreter/src/discovery.rs | 7 +++++-- crates/uv-interpreter/src/lib.rs | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/uv-interpreter/src/discovery.rs b/crates/uv-interpreter/src/discovery.rs index 129b4ddca..e9516f48a 100644 --- a/crates/uv-interpreter/src/discovery.rs +++ b/crates/uv-interpreter/src/discovery.rs @@ -165,8 +165,8 @@ pub enum Error { #[error(transparent)] PyLauncher(#[from] crate::py_launcher::Error), - #[error("Interpreter discovery for `{0}` requires `{1}` but it is not selected")] - SourceNotSelected(InterpreterRequest, InterpreterSource), + #[error("Interpreter discovery for `{0}` requires `{1}` but it is not selected; the following are selected: {2}")] + SourceNotSelected(InterpreterRequest, InterpreterSource, SourceSelector), } /// Lazily iterate over all discoverable Python executables. @@ -466,6 +466,7 @@ pub fn find_interpreter( return Err(Error::SourceNotSelected( request.clone(), InterpreterSource::ProvidedPath, + sources.clone(), )); } if !path.try_exists()? { @@ -484,6 +485,7 @@ pub fn find_interpreter( return Err(Error::SourceNotSelected( request.clone(), InterpreterSource::ProvidedPath, + sources.clone(), )); } if !path.try_exists()? { @@ -508,6 +510,7 @@ pub fn find_interpreter( return Err(Error::SourceNotSelected( request.clone(), InterpreterSource::SearchPath, + sources.clone(), )); } let Some(executable) = which(name).ok() else { diff --git a/crates/uv-interpreter/src/lib.rs b/crates/uv-interpreter/src/lib.rs index f49a7531b..b8ab079d1 100644 --- a/crates/uv-interpreter/src/lib.rs +++ b/crates/uv-interpreter/src/lib.rs @@ -1421,7 +1421,11 @@ mod tests { matches!( result, Err(Error::Discovery( - crate::discovery::Error::SourceNotSelected(_, InterpreterSource::ProvidedPath) + crate::discovery::Error::SourceNotSelected( + _, + InterpreterSource::ProvidedPath, + _ + ) )) ), // TODO(zanieb): We should allow this, just enforce it's a virtualenv