-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Issue #11637] Use suffix on uvx binary when searching for uv binary #11925
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
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:
|
@zanieb Is there anything more I can do at this point to help get this fix/change merged? |
I don't think so, sorry — just about finding time to review. @Gankra can you own this? |
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 like the idea, but if we're willing to fallback to uv
then it doesn't make sense to consider it an error for the uvx
binary to have a weird/unparseable name. At most we could emit a warning?
24d1435
to
4088451
Compare
4088451
to
f1b9878
Compare
@Gankra I updated the code to emit a warning when falling back, and also to fall back when there is an issue in finding the extension for the |
This is a rebased and updated version of #11925 based on my review (I didn't have permission to push to their branch). For posterity I've preserved their commits but my final commit essentially rewrites the whole thing anyway. Fixes #11637 --------- Co-authored-by: Chris Lieb <[email protected]>
Ah, sorry for the race, I've merged my impl! I should have mentioned I was going to push up a cleanup (incredible response time on a PR this old, wow!). Thanks for the great idea/contribution! |
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]
->uv
[email protected]
and observe that it emits a warning about falling back to bareuv
, followed by normaluvx
output[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