From 0f4f3b4714c2d65f7b8891f404f63e154a3273cb Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 7 Jun 2024 15:28:59 -0400 Subject: [PATCH] Update `uv run` and `uv tool run` to use `Toolchain::find` (#4134) Extends https://github.com/astral-sh/uv/pull/4121 --- crates/uv/src/commands/project/run.rs | 12 ++++++++---- crates/uv/src/commands/tool/run.rs | 15 +++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 531cf90e4..d7dcb0e3a 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -108,11 +108,15 @@ pub(crate) async fn run( // Discover an interpreter. let interpreter = if let Some(project_env) = &project_env { project_env.interpreter().clone() - } else if let Some(python) = python.as_ref() { - Toolchain::find_requested(python, SystemPython::Allowed, preview, cache)? - .into_interpreter() } else { - Toolchain::find_default(preview, cache)?.into_interpreter() + // Note we force preview on during `uv run` for now since the entire interface is in preview + Toolchain::find( + python.as_deref(), + SystemPython::Allowed, + PreviewMode::Enabled, + cache, + )? + .into_interpreter() }; // TODO(charlie): If the environment satisfies the requirements, skip creation. diff --git a/crates/uv/src/commands/tool/run.rs b/crates/uv/src/commands/tool/run.rs index 3812a418b..546681d8e 100644 --- a/crates/uv/src/commands/tool/run.rs +++ b/crates/uv/src/commands/tool/run.rs @@ -52,13 +52,16 @@ pub(crate) async fn run( debug!("Syncing ephemeral environment."); // Discover an interpreter. - let interpreter = if let Some(python) = python.as_ref() { - Toolchain::find_requested(python, SystemPython::Allowed, preview, cache)?.into_interpreter() - } else { - Toolchain::find_default(preview, cache)?.into_interpreter() - }; + // Note we force preview on during `uv tool run` for now since the entire interface is in preview + let interpreter = Toolchain::find( + python.as_deref(), + SystemPython::Allowed, + PreviewMode::Enabled, + cache, + )? + .into_interpreter(); - // Create a virtual environment + // Create a virtual environment1 // TODO(zanieb): Move this path derivation elsewhere let uv_state_path = std::env::current_dir()?.join(".uv"); fs_err::create_dir_all(&uv_state_path)?;