Skip to content

[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

Closed

Conversation

cliebBS
Copy link
Contributor

@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. Rename [email protected] -> uv
  7. Run [email protected] and observe that it emits a warning about falling back to bare uv, followed by normal uvx output
warning: Unable to find /Users/jane.doe/code/uv/target/debug/[email protected], defaulting to /Users/jane.doe/code/uv/target/debug/uv
Provide a command to run with `uvx <command>`.

The following tools are installed:

- keyring v25.5.0

See `uvx --help` for more information.
  1. 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 48
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
Contributor 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
Contributor 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
Contributor 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

@cliebBS
Copy link
Contributor Author

cliebBS commented Mar 12, 2025

@zanieb Is there anything more I can do at this point to help get this fix/change merged?

@zanieb
Copy link
Member

zanieb commented Apr 16, 2025

I don't think so, sorry — just about finding time to review.

@Gankra can you own this?

@Gankra Gankra self-requested a review April 16, 2025 15:28
@Gankra Gankra self-assigned this Apr 16, 2025
Copy link
Contributor

@Gankra Gankra left a 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?

@Gankra
Copy link
Contributor

Gankra commented Apr 16, 2025

@cliebBS cliebBS force-pushed the feature/111637/pipx-suffix-uvx branch from 24d1435 to 4088451 Compare April 16, 2025 18:29
@cliebBS cliebBS force-pushed the feature/111637/pipx-suffix-uvx branch from 4088451 to f1b9878 Compare April 16, 2025 18:33
@cliebBS
Copy link
Contributor Author

cliebBS commented Apr 16, 2025

@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 uvx binary. It will now only fail if no uv is found at all.

Gankra added a commit that referenced this pull request Apr 16, 2025
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]>
@Gankra
Copy link
Contributor

Gankra commented Apr 16, 2025

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!

@Gankra Gankra closed this Apr 16, 2025
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
3 participants