From fd52fe74ce459040ade4dc250efbff07ec476ee6 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 10 Jun 2024 16:07:45 -0400 Subject: [PATCH] Update the `Toolchain::find_requested` API to take a parsed request (#4215) Pulled out of https://github.com/astral-sh/uv/pull/4206, need this for #4214 --- crates/uv-toolchain/src/toolchain.rs | 8 ++++---- crates/uv/src/commands/pip/compile.rs | 3 ++- crates/uv/src/commands/project/lock.rs | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/uv-toolchain/src/toolchain.rs b/crates/uv-toolchain/src/toolchain.rs index e3b5d300b..ac458de2b 100644 --- a/crates/uv-toolchain/src/toolchain.rs +++ b/crates/uv-toolchain/src/toolchain.rs @@ -33,7 +33,8 @@ impl Toolchain { cache: &Cache, ) -> Result { if let Some(python) = python { - Self::find_requested(python, system, preview, cache) + let request = ToolchainRequest::parse(python); + Self::find_requested(&request, system, preview, cache) } else if system.is_preferred() { Self::find_default(preview, cache) } else { @@ -60,14 +61,13 @@ impl Toolchain { /// Find an installed [`Toolchain`] that satisfies a request. pub fn find_requested( - request: &str, + request: &ToolchainRequest, system: SystemPython, preview: PreviewMode, cache: &Cache, ) -> Result { let sources = ToolchainSources::from_settings(system, preview); - let request = ToolchainRequest::parse(request); - let toolchain = find_toolchain(&request, system, &sources, cache)??; + let toolchain = find_toolchain(request, system, &sources, cache)??; Ok(toolchain) } diff --git a/crates/uv/src/commands/pip/compile.rs b/crates/uv/src/commands/pip/compile.rs index 6d1aa3eff..24c3b0d2a 100644 --- a/crates/uv/src/commands/pip/compile.rs +++ b/crates/uv/src/commands/pip/compile.rs @@ -161,7 +161,8 @@ pub(crate) async fn pip_compile( SystemPython::Allowed }; let interpreter = if let Some(python) = python.as_ref() { - Toolchain::find_requested(python, system, preview, &cache) + let request = ToolchainRequest::parse(python); + Toolchain::find_requested(&request, system, preview, &cache) } else { // TODO(zanieb): The split here hints at a problem with the abstraction; we should be able to use // `Toolchain::find(...)` here. diff --git a/crates/uv/src/commands/project/lock.rs b/crates/uv/src/commands/project/lock.rs index 67b468b21..6ac5ff0af 100644 --- a/crates/uv/src/commands/project/lock.rs +++ b/crates/uv/src/commands/project/lock.rs @@ -49,7 +49,8 @@ pub(crate) async fn lock( if request.satisfied(&interpreter, cache) { interpreter } else { - Toolchain::find_requested(python, SystemPython::Allowed, preview, cache)? + let request = ToolchainRequest::parse(python); + Toolchain::find_requested(&request, SystemPython::Allowed, preview, cache)? .into_interpreter() } } else {