Improve debug log for interpreter requests during project commands (#6120)

While it's slightly more convenient to log this where we were, it was
pretty unhelpful e.g.

```
DEBUG Interpreter meets the requested Python: `Python >=3.9`
```

What interpreter are we referring to here?
This commit is contained in:
Zanie Blue 2024-08-15 20:30:59 -05:00 committed by GitHub
parent fb6b3ff410
commit 1311127991
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 24 deletions

View File

@ -139,24 +139,6 @@ fn find_environment(
PythonEnvironment::from_root(workspace.venv(), cache) PythonEnvironment::from_root(workspace.venv(), cache)
} }
/// Check if the given interpreter satisfies the project's requirements.
fn interpreter_meets_requirements(
interpreter: &Interpreter,
requested_python: Option<&PythonRequest>,
cache: &Cache,
) -> bool {
let Some(request) = requested_python else {
return true;
};
if request.satisfied(interpreter, cache) {
debug!("Interpreter meets the requested Python: `{request}`");
true
} else {
debug!("Interpreter does not meet the request: `{request}`");
false
}
}
#[derive(Debug)] #[derive(Debug)]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
pub(crate) enum FoundInterpreter { pub(crate) enum FoundInterpreter {
@ -226,17 +208,23 @@ impl FoundInterpreter {
// Read from the virtual environment first. // Read from the virtual environment first.
match find_environment(workspace, cache) { match find_environment(workspace, cache) {
Ok(venv) => { Ok(venv) => {
if interpreter_meets_requirements( if python_request.as_ref().map_or(true, |request| {
venv.interpreter(), if request.satisfied(venv.interpreter(), cache) {
python_request.as_ref(), debug!("The virtual environment's Python version satisfies `{request}`");
cache, true
) { } else {
debug!(
"The virtual environment's Python version does not satisfy `{request}`"
);
false
}
}) {
if let Some(requires_python) = requires_python.as_ref() { if let Some(requires_python) = requires_python.as_ref() {
if requires_python.contains(venv.interpreter().python_version()) { if requires_python.contains(venv.interpreter().python_version()) {
return Ok(Self::Environment(venv)); return Ok(Self::Environment(venv));
} }
debug!( debug!(
"Interpreter does not meet the project's Python requirement: `{requires_python}`" "The virtual environment's Python version does not meet the project's Python requirement: `{requires_python}`"
); );
} else { } else {
return Ok(Self::Environment(venv)); return Ok(Self::Environment(venv));