-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Issue #11637] Use suffix on uvx binary when searching for uv binary #11925
base: main
Are you sure you want to change the base?
Conversation
crates/uv/src/bin/uvx.rs
Outdated
let Some(file_name_str) = os_file_name.to_str() else { | ||
return Err(std::io::Error::new( | ||
std::io::ErrorKind::NotFound, | ||
"Could not determine the file name of the `uvx` binary", | ||
)); | ||
}; | ||
let Some(file_name_no_ext) = file_name_str.strip_suffix(std::env::consts::EXE_SUFFIX) else { | ||
return Err(std::io::Error::new( | ||
std::io::ErrorKind::NotFound, | ||
"Could not determine the file name of the `uvx` binary", | ||
)); | ||
}; | ||
let Some(uvx_suffix) = file_name_no_ext.strip_prefix("uvx") else { | ||
return Err(std::io::Error::new( | ||
std::io::ErrorKind::NotFound, | ||
"Could not determine the file name of the `uvx` binary", | ||
)); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should all these error cases have different error messages? Seems helpful to distinguish between them if someone actually encounters these failures.
Does it make sense to use a io:Error
here? NotFound
seems weird in this context, though I'm not sure if it's worth complicating the run
signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure how much of the details we wanted to expose to users. I updated the code to have distinct error messages for each potential error situation, switched a couple of places to use InvalidData
as the error kind instead of NotFound
, and removed one of the error cases entirely in favor of using a fallback value.
I think this makes sense to me. Thanks for taking the time to contribute it. Do you think we should fallback to |
Falling back to plain
|
This assumes that |
Ok, it now does the following:
|
Summary
When running uvx that has been installed using a pipx suffix, the corresponding uv binary cannot be found due to uvx always looking for an executable called
uv
on the PATH, while it has instead been installed using a suffix. This change makes it so that uvx discovers the suffix to its name and then searches for a uv binary with the same suffix. For example, if uvx is called[email protected]
, then it will search for[email protected]
instead ofuv
.Test Plan
uv
anduvx
binaries from the PATHmain
uvx
->[email protected]
anduv
->[email protected]
[email protected]
and observe that it produces the following output:[email protected]
and[email protected]
binariesuvx
and observe that it behaves like normal (maintains current behavior)uvx
->[email protected]
anduv
->[email protected]
[email protected]
and observe that it behaves like normal (exhibits correct behavior for suffixed executable names)[email protected]
[email protected]
and observe that it presents an error message stating thatuv
could not be found either with the suffixed name or with the bare nameResolves #11637