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));