Skip to content

feat(uv): add @uv//bin:bin and //python/uv/bin:uv targets to run uv - #4371

Open
rickeylev wants to merge 2 commits into
bazel-contrib:mainfrom
rickeylev:support_uv_binary_execution
Open

rickeylev wants to merge 2 commits into
bazel-contrib:mainfrom
rickeylev:support_uv_binary_execution

Conversation

@rickeylev

@rickeylev rickeylev commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Users could not run the Bazel-configured uv binary directly because
//python/uv:current_toolchain had restricted visibility and omitted
the underlying uv binary from its runfiles and executable symlink
flag.

Make //python/uv:current_toolchain public, mark its symlink executable
while preserving any file extension (such as .exe on Windows),
include the underlying uv binary in its runfiles, and expose the
$(UV) Make variable alongside $(UV_BIN). Expose convenient public
aliases at @uv//bin:bin, //python/uv/bin:bin, and
//python/uv/bin:uv so users can invoke uv directly via bazel run.

Open question: what target should we expose this as? Which aliases, if
any, should we have?

Users could not run the Bazel-configured `uv` binary directly because
`//python/uv:current_toolchain` had restricted visibility and omitted
the underlying `uv` binary from its runfiles and executable symlink
flag.

Make `//python/uv:current_toolchain` public, mark its symlink executable
while preserving any file extension (such as `.exe` on Windows), and
include the underlying `uv` binary in its runfiles. Expose convenient
public aliases at `@uv//bin:bin`, `//python/uv/bin:bin`, and
`//python/uv/bin:uv` so users can invoke `uv` directly via `bazel run`.
@rickeylev
rickeylev requested a review from aignas as a code owner October 27, 2026 23:44
@rickeylev

Copy link
Copy Markdown
Collaborator Author

AI Disclosure: This pull request was developed with the assistance of an AI coding agent (semi-autonomous, directed and reviewed by @rickeylev / @rlevasseur).

PR Comment Handling: Review comments on this PR will be reviewed and addressed with human oversight before any responses or follow-up changes are posted.

This is an automatically generated agent comment.

@rickeylev rickeylev added the do not merge Tag that prevents merging label Oct 27, 2026
@rickeylev

Copy link
Copy Markdown
Collaborator Author

The targets I like most are:

  • bazel run @rules_python//python/uv
  • bazel run @uv (expands to @uv//:uv)

But both of those names are somewhat taken. Read below.

//python/uv:uv.bzl%uv is, unfortunately, the bzlmod extension identifier. This makes re-using it rather difficult.

We could make the //python/uv:uv target an alias to current_toolchain. This will make the gazelle auto-generation mad because the :uv target is currently being used for bzl_library(name="uv", srcs=[uv.bzl]). That target shouldn't be used in practice, though (bzlmod doesn't operate on targets like that).

I like the brevity of e.g. bazel run @uv, but what I don't like is it requires users to add use_repo() to their MODULE.bazel. It's also unfortunate that all the toolchains are put directly in the root of the @uv module, so @uv//:bin ends up being the same package as all the toolchain registrations. If its an alias, I don't think that would be too bad? (IMHO we should move the toolchains to sub-directory; i tihnk we can do that without it being a breaking change?).

The next best option IMHO is @rules_python//python/uv:bin`

And we can create an alias in the @uv repo somewhere. Maybe @uv//bin ?

@aignas @jvolkman thoughts?

Comment thread docs/api/rules_python/python/uv/bin/index.md
Comment thread tests/uv/toolchain/BUILD.bazel
Define `$(UV)` alongside `$(UV_BIN)` in `//python/uv:current_toolchain`
and document `bazel_env.bzl` usage per review feedback. Update
`uv_help_test.py` to match `uv.exe` in Windows `--help` output.
@aignas

aignas commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Extra:

  • @rules_python//bin/uv or bin:uv

That said, in addition to those, we should provide @UV so that users have a choice. :)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Tag that prevents merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants