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
This commit is contained in:
Zanie Blue 2024-06-05 08:26:56 -04:00 committed by GitHub
parent 054fffe05e
commit 2be93c0b2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -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 {

View File

@ -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