From 131112799104aaf91fd11f85bf21b09c6f45665f Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 15 Aug 2024 20:30:59 -0500 Subject: [PATCH] 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? --- crates/uv/src/commands/project/mod.rs | 36 +++++++++------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/crates/uv/src/commands/project/mod.rs b/crates/uv/src/commands/project/mod.rs index 4cf74c6b4..ad0b5cbb5 100644 --- a/crates/uv/src/commands/project/mod.rs +++ b/crates/uv/src/commands/project/mod.rs @@ -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 { @@ -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));