Skip to content

Commit

Permalink
Address review comments: Optional RunCommand
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <[email protected]>
  • Loading branch information
kakkoyun committed Sep 26, 2024
1 parent f9a62eb commit 4c7f9bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::settings::ResolverInstallerSettings;
pub(crate) async fn run(
project_dir: &Path,
script: Option<Pep723Script>,
command: RunCommand,
command: Option<RunCommand>,
requirements: Vec<RequirementsSource>,
show_resolution: bool,
locked: bool,
Expand Down Expand Up @@ -721,7 +721,7 @@ pub(crate) async fn run(

// Check if any run command is given.
// If not, print the available scripts for the current interpreter.
if let RunCommand::Empty = command {
let Some(command) = command else {
writeln!(
printer.stdout(),
"Provide a command or script to invoke with `uv run <command>` or `uv run <script>.py`.\n"
Expand Down Expand Up @@ -753,7 +753,7 @@ pub(crate) async fn run(
.filter(|path| is_executable(path))
.map(|path| {
if cfg!(windows) {
// remove the extensions
// Remove the extensions.
path.with_extension("")
} else {
path
Expand All @@ -766,7 +766,7 @@ pub(crate) async fn run(
.to_string()
})
.filter(|command| {
!command.starts_with("activate") || !command.starts_with("deactivate")
!command.starts_with("activate") && !command.starts_with("deactivate")
})
.collect_vec();
commands.sort();
Expand Down
14 changes: 6 additions & 8 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ async fn run(cli: Cli) -> Result<ExitStatus> {

// Parse the external command, if necessary.
let run_command = if let Commands::Project(command) = &*cli.command {
if let ProjectCommand::Run(uv_cli::RunArgs { command, .. }) = &**command {
match command {
Some(command) => Some(RunCommand::try_from(command)?),
None => Some(RunCommand::Empty),
}
if let ProjectCommand::Run(uv_cli::RunArgs {
command: Some(command),
..
}) = &**command
{
Some(RunCommand::try_from(command)?)
} else {
None
}
Expand Down Expand Up @@ -1230,9 +1231,6 @@ async fn run_project(
)
.collect::<Vec<_>>();

// Given `ProjectCommand::Run`, we always expect a `RunCommand` to be present.
let command = command.expect("run command is required");

Box::pin(commands::run(
project_dir,
script,
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ fn run_no_args() -> Result<()> {

#[cfg(windows)]
uv_snapshot!(context.filters(), context.run(), @r###"
success: true
exit_code: 0
success: false
exit_code: 1
----- stdout -----
Provide a command or script to invoke with `uv run <command>` or `uv run <script>.py`.
Expand Down

0 comments on commit 4c7f9bd

Please sign in to comment.