Skip to content

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

Merged
rickeylev merged 5 commits into
bazel-contrib:mainfrom
rickeylev:support_uv_binary_execution
Oct 30, 2026
Merged

rickeylev merged 5 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//:uv and //python/uv/bin:uv so users can invoke uv
directly via bazel run.

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 tests/uv/toolchain/BUILD.bazel Resolved
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. :)

Use @uv//:uv as the sole uv binary alias in the @UV repository so users can run `bazel run @uv` or `bazel run @uv//:uv` directly without a separate bin subpackage.
@rickeylev rickeylev changed the title feat(uv): add @uv//bin:bin and //python/uv/bin:uv targets to run uv feat(uv): add @uv//:uv and //python/uv/bin:uv targets to run uv Oct 30, 2026
Exposing two aliases inside //python/uv/bin adds redundant API surface
when @uv//:uv already provides package-shorthand execution (`bazel run
@uv`). Keep //python/uv/bin:uv as the sole alias in //python/uv/bin
and update its documentation, news entry, and toolchain test.
@rickeylev rickeylev removed the do not merge Tag that prevents merging label Oct 30, 2026
Users inspecting //python/uv:current_toolchain in the API reference
could miss the shorter aliases that forward to it. Note both
//python/uv/bin:uv and @uv//:uv in the current_toolchain target
documentation.
@rickeylev
rickeylev enabled auto-merge October 30, 2026 07:23
@rickeylev
rickeylev added this pull request to the merge queue Oct 30, 2026
Merged via the queue into bazel-contrib:main with commit 9699f18 Oct 30, 2026
13 checks passed
@rickeylev
rickeylev deleted the support_uv_binary_execution branch October 30, 2026 07:57
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.

2 participants