Skip to content

Commit

Permalink
Improve debug log for interpreter requests during project commands (#…
Browse files Browse the repository at this point in the history
…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?
  • Loading branch information
zanieb authored Aug 16, 2024
1 parent fb6b3ff commit 1311127
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions crates/uv/src/commands/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,6 @@ fn find_environment(
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)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum FoundInterpreter {
Expand Down Expand Up @@ -226,17 +208,23 @@ impl FoundInterpreter {
// Read from the virtual environment first.
match find_environment(workspace, cache) {
Ok(venv) => {
if interpreter_meets_requirements(
venv.interpreter(),
python_request.as_ref(),
cache,
) {
if python_request.as_ref().map_or(true, |request| {
if request.satisfied(venv.interpreter(), cache) {
debug!("The virtual environment's Python version satisfies `{request}`");
true
} else {
debug!(
"The virtual environment's Python version does not satisfy `{request}`"
);
false
}
}) {
if let Some(requires_python) = requires_python.as_ref() {
if requires_python.contains(venv.interpreter().python_version()) {
return Ok(Self::Environment(venv));
}
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 {
return Ok(Self::Environment(venv));
Expand Down

0 comments on commit 1311127

Please sign in to comment.