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

[Issue #11637] Use suffix on uvx binary when searching for uv binary #11925

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cliebBS
Copy link

@cliebBS cliebBS commented Mar 3, 2025

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 of uv.

Test Plan

  1. Remove all uv and uvx binaries from the PATH
  2. Build code on main
  3. Rename uvx -> [email protected] and uv -> [email protected]
  4. Run [email protected] and observe that it produces the following output:
error: Could not find the `uv` binary at: /Users/me/.local/bin/uv
  1. Delete the [email protected] and [email protected] binaries
  2. Build the code on this branch
  3. Run uvx and observe that it behaves like normal (maintains current behavior)
  4. Rename uvx -> [email protected] and uv -> [email protected]
  5. Run [email protected] and observe that it behaves like normal (exhibits correct behavior for suffixed executable names)
  6. Delete [email protected]
  7. Run [email protected] and observe that it presents an error message stating that uv could not be found either with the suffixed name or with the bare name
error: Could not find uv binary at /Users/jane.doe/uv/target/debug/[email protected] or /Users/jane.doe/uv/target/debug/uv

Resolves #11637

@cliebBS cliebBS changed the title [Issue 111637] Use suffix on uvx binary when searching for uv binary [Issue 11637] Use suffix on uvx binary when searching for uv binary Mar 3, 2025
@cliebBS cliebBS changed the title [Issue 11637] Use suffix on uvx binary when searching for uv binary [Issue #11637] Use suffix on uvx binary when searching for uv binary Mar 3, 2025
Comment on lines 33 to 50
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",
));
};
Copy link
Member

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.

Copy link
Author

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.

@zanieb
Copy link
Member

zanieb commented Mar 3, 2025

I think this makes sense to me. Thanks for taking the time to contribute it.

Do you think we should fallback to uv if uv-suffix does not exist? I think we might need to for backwards compatibility?

@zanieb zanieb self-assigned this Mar 3, 2025
@cliebBS
Copy link
Author

cliebBS commented Mar 3, 2025

Falling back to plain uv when uv{suffix} doesn't exist I think has a couple of problems:

  1. There's no guarantee that there will be a uv on the system. Doing a suffixed install using pipx will rename all binaries to use the suffix, so you'd actually need a separate installation of uv on your system to have the fallback option in place
  2. Falling back to bare uv can result in a different version of uv being used to execute the command than the version of uvx that is trying to exec the command. While this would work for now, if a breaking change were made to uv tool uvx or uv tool run in the future (this is still a 0.x product, after all), it could result in uvx{suffix} becoming incompatible with uv and likely producing some very confusing errors for the user

@zanieb
Copy link
Member

zanieb commented Mar 3, 2025

This assumes that pipx is the only reason that the binary would have a different name though, which I'm not comfortable with.

@cliebBS
Copy link
Author

cliebBS commented Mar 3, 2025

Ok, it now does the following:

  1. Run uv{suffix} if it is present in uvx directory
  2. Run uv if it is present in uvx directory
  3. Provide an error message that includes the names we tried to use to find uv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uvx does not work when installed with pipx install --suffix=... uv
2 participants