From 9b870f20f1c6ce12b7e5b94eeb66774fc3ae06f3 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 22 May 2024 21:59:04 -0400 Subject: [PATCH] Allow specification of additional requirements in `uv tool run` (#3678) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows requesting additional transitive dependencies when running a tool. e.g. `uv tool run -v --with anyio ruff check example.py` (Why would you want anyio with ruff? Who knows 😄) The motivation for doing this now is that I think the first implementation of `uv tool install` might just shim into `uv tool run` with pinned dependencies? Regardless this is something we need in the long run and is a trivial addition right now. --- crates/uv/src/cli.rs | 4 ++++ crates/uv/src/commands/tool/run.rs | 7 +++++-- crates/uv/src/main.rs | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/uv/src/cli.rs b/crates/uv/src/cli.rs index 4bdc8a398..3356f1674 100644 --- a/crates/uv/src/cli.rs +++ b/crates/uv/src/cli.rs @@ -1946,6 +1946,10 @@ pub(crate) struct ToolRunArgs { #[arg(long)] pub(crate) from: Option, + /// Include the following extra requirements. + #[arg(long)] + pub(crate) with: Vec, + /// The Python interpreter to use to build the run environment. #[arg( long, diff --git a/crates/uv/src/commands/tool/run.rs b/crates/uv/src/commands/tool/run.rs index c7cddddcc..20164d688 100644 --- a/crates/uv/src/commands/tool/run.rs +++ b/crates/uv/src/commands/tool/run.rs @@ -25,6 +25,7 @@ pub(crate) async fn run( args: Vec, python: Option, from: Option, + with: Vec, _isolated: bool, preview: PreviewMode, connectivity: Connectivity, @@ -35,10 +36,12 @@ pub(crate) async fn run( warn_user!("`uv tool run` is experimental and may change without warning."); } - // TODO(zanieb): Allow users to pass additional requirements let requirements = [RequirementsSource::from_package( from.unwrap_or_else(|| target.clone()), - )]; + )] + .into_iter() + .chain(with.into_iter().map(RequirementsSource::from_package)) + .collect::>(); // TODO(zanieb): When implementing project-level tools, discover the project and check if it has the tool // TOOD(zanieb): Determine if we sould layer on top of the project environment if it is present diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index 8dd6fc175..2020f798f 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -622,6 +622,7 @@ async fn run() -> Result { args.args, args.python, args.from, + args.with, globals.isolated, globals.preview, globals.connectivity,