Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uvx warn when no executables are available #5675

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
"###);
}
Loading