Skip to content

Commit

Permalink
Default to python when uv run does not recieve a command (#3109)
Browse files Browse the repository at this point in the history
This means that a bare `uv run` invocation drops you into a REPL.

This behavior is internally controversial, and may best be served by a
dedicated `uv repl` command. I would imagine it's important to fail if
no command is given in _some_ circumstances, but those may be resolved
by _not_ doing this if we do not detect a TTY.

Regardless, I'm interested in giving this a try for a bit during this
experimental phase.
  • Loading branch information
zanieb authored Apr 19, 2024
1 parent 9bcc194 commit 31765c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,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<String>,

/// The arguments to the command.
#[arg(allow_hyphen_values = true)]
Expand Down
7 changes: 5 additions & 2 deletions crates/uv/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ 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<String>,
args: Vec<String>,
mut requirements: Vec<RequirementsSource>,
isolated: bool,
no_workspace: bool,
cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
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
Expand Down Expand Up @@ -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?;

Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ async fn run() -> Result<ExitStatus> {
.collect::<Vec<_>>();

commands::run(
args.command,
args.target,
args.args,
requirements,
args.isolated,
Expand Down

0 comments on commit 31765c0

Please sign in to comment.