From db9246fdae08cb1f08a38938e524f867a73a2a9b Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 17 Apr 2024 17:13:02 -0500 Subject: [PATCH] Default to `python` when `uv run` does not recieve a command --- crates/uv/src/cli.rs | 2 +- crates/uv/src/commands/run.rs | 7 +++++-- crates/uv/src/main.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/uv/src/cli.rs b/crates/uv/src/cli.rs index 12ba381e271d..92c83d7e7c39 100644 --- a/crates/uv/src/cli.rs +++ b/crates/uv/src/cli.rs @@ -1343,7 +1343,7 @@ pub(crate) struct VenvArgs { #[allow(clippy::struct_excessive_bools)] pub(crate) struct RunArgs { /// The command to run. - pub(crate) command: String, + pub(crate) target: Option, /// The arguments to the command. #[arg(allow_hyphen_values = true)] diff --git a/crates/uv/src/commands/run.rs b/crates/uv/src/commands/run.rs index 3c4e43b9c506..c5e88fb740b6 100644 --- a/crates/uv/src/commands/run.rs +++ b/crates/uv/src/commands/run.rs @@ -39,7 +39,7 @@ use uv_types::{BuildIsolation, EmptyInstalledPackages, HashStrategy, InFlight}; /// Run a command. #[allow(clippy::unnecessary_wraps, clippy::too_many_arguments)] pub(crate) async fn run( - command: String, + target: Option, args: Vec, mut requirements: Vec, isolated: bool, @@ -47,6 +47,8 @@ pub(crate) async fn run( cache: &Cache, printer: Printer, ) -> Result { + let command = target.unwrap_or("python".to_string()); + // Copy the requirements into a set of overrides; we'll use this to prioritize // requested requirements over those discovered in the project. // We must retain these requirements as direct dependencies too, as overrides @@ -88,7 +90,8 @@ pub(crate) async fn run( // Spawn and wait for completion // Standard input, output, and error streams are all inherited // TODO(zanieb): Throw a nicer error message if the command is not found - debug!("Running `{command} {}`", args.join(" ")); + let space = if args.is_empty() { "" } else { " " }; + debug!("Running `{command}{space}{}`", args.join(" ")); let mut handle = process.spawn()?; let status = handle.wait().await?; diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index 52022e3d6f06..d7566e3717b8 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -582,7 +582,7 @@ async fn run() -> Result { .collect::>(); commands::run( - args.command, + args.target, args.args, requirements, args.isolated,