Skip to content

Commit

Permalink
uvx warn when no executables are available
Browse files Browse the repository at this point in the history
  • Loading branch information
blueraft committed Jul 31, 2024
1 parent b0e3785 commit e65c306
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
20 changes: 12 additions & 8 deletions crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,17 @@ pub(crate) async fn run(
"The executable `{}` was not found.",
executable.to_string_lossy().cyan(),
)?;
if !entrypoints.is_empty() {
if entrypoints.is_empty() {
warn_user!(
"Package `{}` does not provide any executables.",
from.name.red()
);
} else {
warn_user!(
"An executable named `{}` is not provided by package `{}`.",
executable.to_string_lossy().cyan(),
from.name.red()
);
writeln!(
printer.stdout(),
"The following executables are provided by `{}`:",
Expand Down Expand Up @@ -230,13 +240,7 @@ fn warn_executable_not_provided_by_package(
.any(|package| package.name() == from_package)
{
match packages.as_slice() {
[] => {
warn_user!(
"An executable named `{}` is not provided by package `{}`.",
executable.cyan(),
from_package.red()
);
}
[] => {}
[package] => {
let suggested_command = format!(
"{invocation_source} --from {} {}",
Expand Down
31 changes: 30 additions & 1 deletion crates/uv/tests/tool_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn tool_run_suggest_valid_commands() {
+ fastapi-cli==0.0.1
+ importlib-metadata==1.7.0
+ zipp==3.18.1
warning: An executable named `fastapi-cli` is not provided by package `fastapi-cli`.
warning: Package `fastapi-cli` does not provide any executables.
"###);
}

Expand Down Expand Up @@ -835,3 +835,32 @@ fn tool_run_without_output() {
warning: `uv tool run` is experimental and may change without warning
"###);
}

#[test]
fn warn_no_executables_found() {
let context = TestContext::new("3.12").with_filtered_exe_suffix();
let tool_dir = context.temp_dir.child("tools");
let bin_dir = context.temp_dir.child("bin");

uv_snapshot!(context.filters(), context.tool_run()
.arg("requests")
.env("UV_TOOL_DIR", tool_dir.as_os_str())
.env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###"
success: false
exit_code: 1
----- stdout -----
The executable `requests` was not found.
----- stderr -----
warning: `uv tool run` is experimental and may change without warning
Resolved 5 packages in [TIME]
Prepared 5 packages in [TIME]
Installed 5 packages in [TIME]
+ certifi==2024.2.2
+ charset-normalizer==3.3.2
+ idna==3.6
+ requests==2.31.0
+ urllib3==2.2.1
warning: Package `requests` does not provide any executables.
"###);
}

0 comments on commit e65c306

Please sign in to comment.