From b6020c5053dd229c3a46c7d4b216d97c0783435d Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 20 May 2024 14:10:01 -0400 Subject: [PATCH] Allow users to specify a custom package spec to `uv tool run` --- crates/uv/src/cli.rs | 6 ++++++ crates/uv/src/commands/tool/run.rs | 8 +++++--- crates/uv/src/main.rs | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/uv/src/cli.rs b/crates/uv/src/cli.rs index 2f47172fef12..b43a41b1bab4 100644 --- a/crates/uv/src/cli.rs +++ b/crates/uv/src/cli.rs @@ -1945,6 +1945,12 @@ pub(crate) struct ToolRunArgs { #[arg(allow_hyphen_values = true)] pub(crate) args: Vec, + /// Use the given package to provide the command. + /// + /// By default, the package name is assumed to match the command name. + #[arg(long)] + pub(crate) from: Option, + /// 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 7b82f6d2caf3..1d0a5737bfb5 100644 --- a/crates/uv/src/commands/tool/run.rs +++ b/crates/uv/src/commands/tool/run.rs @@ -23,6 +23,7 @@ pub(crate) async fn run( target: String, args: Vec, python: Option, + from: Option, _isolated: bool, preview: PreviewMode, cache: &Cache, @@ -32,9 +33,10 @@ pub(crate) async fn run( warn_user!("`uv tool run` is experimental and may change without warning."); } - // TODO(zanieb): Allow users to pass an explicit package name different than the target - // as well as additional requirements - let requirements = [RequirementsSource::from_package(target.clone())]; + // TODO(zanieb): Allow users to pass additional requirements + let requirements = [RequirementsSource::from_package( + from.unwrap_or_else(|| target.clone()), + )]; // 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 24b31701a565..00b3d175669a 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -607,6 +607,7 @@ async fn run() -> Result { args.target, args.args, args.python, + args.from, globals.isolated, globals.preview, &cache,