From c806585ce39e8672ec388905fb0e381d0db2b48a Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Tue, 27 Oct 2026 16:43:40 -0700 Subject: [PATCH 1/5] feat(uv): add @uv//bin:bin and //python/uv/bin:uv targets to run uv 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`. --- docs/api/rules_python/python/uv/bin/index.md | 32 +++++++++++++++++++ docs/api/rules_python/python/uv/index.md | 27 ++++++++++++++++ docs/pypi/lock.md | 3 ++ news/uv-bin-target.added.md | 4 +++ python/uv/BUILD.bazel | 6 +--- python/uv/bin/BUILD.bazel | 21 ++++++++++++ python/uv/private/current_toolchain.bzl | 18 +++++++++-- python/uv/private/uv.bzl | 13 ++++++++ python/uv/private/uv_register_toolchains.bzl | 3 +- python/uv/private/uv_toolchains_repo.bzl | 9 ++++++ .../bzlmod_lockfile/MODULE.bazel.lock | 2 +- tests/uv/toolchain/BUILD.bazel | 16 ++++++++-- tests/uv/toolchain/uv_help_test.py | 20 ++++++++++++ 13 files changed, 162 insertions(+), 12 deletions(-) create mode 100644 docs/api/rules_python/python/uv/bin/index.md create mode 100644 docs/api/rules_python/python/uv/index.md create mode 100644 news/uv-bin-target.added.md create mode 100644 python/uv/bin/BUILD.bazel diff --git a/docs/api/rules_python/python/uv/bin/index.md b/docs/api/rules_python/python/uv/bin/index.md new file mode 100644 index 0000000000..365389df46 --- /dev/null +++ b/docs/api/rules_python/python/uv/bin/index.md @@ -0,0 +1,32 @@ +:::{default-domain} bzl +::: +:::{bzl:currentfile} //python/uv/bin:BUILD.bazel +::: + +# //python/uv/bin + +::::{bzl:target} bin + +Alias for {obj}`//python/uv:current_toolchain` to directly run the configured +`uv` binary: + +```sh +bazel run @rules_python//python/uv/bin -- --help +``` + +:::{versionadded} VERSION_NEXT_FEATURE +::: +:::: + +::::{bzl:target} uv + +Alias for {obj}`//python/uv:current_toolchain` to directly run the configured +`uv` binary: + +```sh +bazel run @rules_python//python/uv/bin:uv -- --help +``` + +:::{versionadded} VERSION_NEXT_FEATURE +::: +:::: diff --git a/docs/api/rules_python/python/uv/index.md b/docs/api/rules_python/python/uv/index.md new file mode 100644 index 0000000000..ff5f08f5ff --- /dev/null +++ b/docs/api/rules_python/python/uv/index.md @@ -0,0 +1,27 @@ +:::{default-domain} bzl +::: +:::{bzl:currentfile} //python/uv:BUILD.bazel +::: + +# //python/uv + +::::{bzl:target} current_toolchain + +Exposes the resolved `uv` toolchain for the target/execution platform as an +executable target and template variable provider (`$(UV_BIN)`). + +Can be run directly with `bazel run`: + +```sh +bazel run @rules_python//python/uv:current_toolchain -- --help +``` + +:::{versionadded} VERSION_NEXT_FEATURE +::: +:::: + +:::{bzl:target} uv_toolchain_type + +Toolchain type identifier for the `uv` toolchain, implemented by +{obj}`uv_toolchain`. +::: diff --git a/docs/pypi/lock.md b/docs/pypi/lock.md index 727795c1ef..4002627c5d 100644 --- a/docs/pypi/lock.md +++ b/docs/pypi/lock.md @@ -94,6 +94,9 @@ uv.configure(version = "0.13.5") Without `version`, the default version specified by `rules_python` is used. See {obj}`uv.configure` for using a mirror, explicit URLs or extra platforms. +To run the configured `uv` binary directly, run +`bazel run @rules_python//python/uv/bin:uv -- ` (or add +`use_repo(uv, "uv")` and run `bazel run @uv//bin:bin -- `). (uv-workspace-setup)= ##### WORKSPACE diff --git a/news/uv-bin-target.added.md b/news/uv-bin-target.added.md new file mode 100644 index 0000000000..0de9f35eed --- /dev/null +++ b/news/uv-bin-target.added.md @@ -0,0 +1,4 @@ +(uv) Added `@uv//bin:bin`, {obj}`//python/uv/bin:uv`, +{obj}`//python/uv/bin:bin`, and public visibility on +{obj}`//python/uv:current_toolchain` to run the configured `uv` binary directly +(e.g. `bazel run @uv//bin:bin -- --help`). diff --git a/python/uv/BUILD.bazel b/python/uv/BUILD.bazel index 9551051bd2..e2024650bd 100644 --- a/python/uv/BUILD.bazel +++ b/python/uv/BUILD.bazel @@ -32,11 +32,7 @@ current_toolchain( # Marked manual so that `bazel test //...` passes # even if no toolchain is registered. tags = ["manual"], - # EXPERIMENTAL: Visibility is restricted to allow for changes. - visibility = [ - "//:__subpackages__", - "@rules_python//examples:__subpackages__", - ], + visibility = ["//visibility:public"], ) bzl_library( diff --git a/python/uv/bin/BUILD.bazel b/python/uv/bin/BUILD.bazel new file mode 100644 index 0000000000..ed6b4dcb01 --- /dev/null +++ b/python/uv/bin/BUILD.bazel @@ -0,0 +1,21 @@ +load("//python/private:distribution_filegroup.bzl", "distribution_filegroup") + +package(default_visibility = ["//:__subpackages__"]) + +distribution_filegroup( + name = "distribution", +) + +alias( + name = "bin", + actual = "//python/uv:current_toolchain", + tags = ["manual"], + visibility = ["//visibility:public"], +) + +alias( + name = "uv", + actual = "//python/uv:current_toolchain", + tags = ["manual"], + visibility = ["//visibility:public"], +) diff --git a/python/uv/private/current_toolchain.bzl b/python/uv/private/current_toolchain.bzl index 91a25cb50f..06559c9aab 100644 --- a/python/uv/private/current_toolchain.bzl +++ b/python/uv/private/current_toolchain.bzl @@ -32,12 +32,24 @@ def _current_toolchain_impl(ctx): original_uv_executable = toolchain_info.uv_toolchain_info.uv[DefaultInfo].files_to_run.executable # Use `uv` as the name of the binary to make the help message well formatted - symlink_uv_executable = ctx.actions.declare_file("current_toolchain/uv".format(original_uv_executable.basename)) - ctx.actions.symlink(output = symlink_uv_executable, target_file = original_uv_executable) + if original_uv_executable.extension: + ext = "." + original_uv_executable.extension + else: + ext = "" + symlink_uv_executable = ctx.actions.declare_file( + "{}/uv{}".format(ctx.label.name, ext), + ) + ctx.actions.symlink( + output = symlink_uv_executable, + target_file = original_uv_executable, + is_executable = True, + ) new_default_info = DefaultInfo( files = depset([symlink_uv_executable]), - runfiles = toolchain_info.default_info.default_runfiles, + runfiles = ctx.runfiles(files = [original_uv_executable]).merge( + toolchain_info.default_info.default_runfiles, + ), executable = symlink_uv_executable, ) diff --git a/python/uv/private/uv.bzl b/python/uv/private/uv.bzl index 1ed9794316..20f578cf15 100644 --- a/python/uv/private/uv.bzl +++ b/python/uv/private/uv.bzl @@ -36,8 +36,21 @@ uv = use_extension( uv.configure(version = "0.13.5") ``` +To run `uv` directly: +```sh +bazel run @rules_python//python/uv/bin:uv -- --help +# Or, if `use_repo(uv, "uv")` is in MODULE.bazel: +bazel run @uv//bin:bin -- --help +``` + Since this is only for locking the requirements files, it should be always marked as a `dev_dependency`. + +:::{versionchanged} VERSION_NEXT_FEATURE +Added `@uv//bin:bin` and {obj}`//python/uv/bin:uv` (aliases for +{obj}`//python/uv:current_toolchain`) to run the configured `uv` binary +directly. +::: """ _DEFAULT_ATTRS = { diff --git a/python/uv/private/uv_register_toolchains.bzl b/python/uv/private/uv_register_toolchains.bzl index 1da301159e..179317964e 100644 --- a/python/uv/private/uv_register_toolchains.bzl +++ b/python/uv/private/uv_register_toolchains.bzl @@ -139,7 +139,8 @@ def uv_register_toolchains( This is the WORKSPACE equivalent of the {obj}`uv` module extension. It creates one download repository per `uv` version and platform, and the toolchain hub repository `name` with a `toolchain` for each of them, which - it registers as `@{name}//:all`; {obj}`lock` can then be used. See the + it registers as `@{name}//:all`; {obj}`lock` can then be used, and `uv` can + be run directly via `bazel run @{name}//bin:bin -- `. See the {ref}`WORKSPACE setup guide ` for usage examples. Platforms without an archive in a manifest get no toolchain. The diff --git a/python/uv/private/uv_toolchains_repo.bzl b/python/uv/private/uv_toolchains_repo.bzl index 7e11e0adb6..9ce485b36b 100644 --- a/python/uv/private/uv_toolchains_repo.bzl +++ b/python/uv/private/uv_toolchains_repo.bzl @@ -22,6 +22,14 @@ load("@rules_python//python/uv/private:toolchains_hub.bzl", "toolchains_hub") {} """ +_BIN_BUILD_TEMPLATE = """\ +alias( + name = "bin", + actual = "@rules_python//python/uv:current_toolchain", + visibility = ["//visibility:public"], +) +""" + def _non_empty(d): return {k: v for k, v in d.items() if v} @@ -45,6 +53,7 @@ def _toolchains_repo_impl(repository_ctx): ), ) repository_ctx.file("BUILD.bazel", contents) + repository_ctx.file("bin/BUILD.bazel", _BIN_BUILD_TEMPLATE) uv_toolchains_repo = repository_rule( _toolchains_repo_impl, diff --git a/tests/integration/bzlmod_lockfile/MODULE.bazel.lock b/tests/integration/bzlmod_lockfile/MODULE.bazel.lock index f86bf246f1..1947df0ea0 100644 --- a/tests/integration/bzlmod_lockfile/MODULE.bazel.lock +++ b/tests/integration/bzlmod_lockfile/MODULE.bazel.lock @@ -259,7 +259,7 @@ }, "@@rules_python+//python/uv:uv.bzl%uv": { "general": { - "bzlTransitiveDigest": "a11TI1DxtsKzJJnFDIAhAoVNhub4iqECM+h0qTqOT68=", + "bzlTransitiveDigest": "8ltBqOZd6XrCh2wotsEx0rcRFf6JQORpaK6Pu2/0LYk=", "usagesDigest": "UgEeJTkNLce2eABymcbLBebdHpF0D8qrT6A6PSESotA=", "recordedInputs": [ "REPO_MAPPING:rules_python+,bazel_tools bazel_tools", diff --git a/tests/uv/toolchain/BUILD.bazel b/tests/uv/toolchain/BUILD.bazel index 9017396ffe..8b7275f1f7 100644 --- a/tests/uv/toolchain/BUILD.bazel +++ b/tests/uv/toolchain/BUILD.bazel @@ -10,7 +10,19 @@ genrule( py_test( name = "uv_help_test", srcs = ["uv_help_test.py"], - data = [":uv_help"], - env = {"DATA": "$(rlocationpath :uv_help)"}, + data = [ + ":uv_help", + "//python/uv:current_toolchain", + "//python/uv/bin", + "//python/uv/bin:uv", + "@uv//bin", + ], + env = { + "DATA": "$(rlocationpath :uv_help)", + "UV_BIN": "$(rlocationpath @uv//bin:bin)", + "UV_CURRENT_TOOLCHAIN": "$(rlocationpath //python/uv:current_toolchain)", + "UV_RULES_PYTHON_BIN": "$(rlocationpath //python/uv/bin:bin)", + "UV_RULES_PYTHON_UV": "$(rlocationpath //python/uv/bin:uv)", + }, deps = ["//python/runfiles"], ) diff --git a/tests/uv/toolchain/uv_help_test.py b/tests/uv/toolchain/uv_help_test.py index c4515277f7..23558bb770 100755 --- a/tests/uv/toolchain/uv_help_test.py +++ b/tests/uv/toolchain/uv_help_test.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os +import subprocess import unittest from pathlib import Path @@ -22,6 +23,25 @@ def test_uv_help(self): self.assertIn("Usage: uv [OPTIONS] ", uv_help) + def test_uv_bin(self): + root = runfiles.CreateOrRaise().root() + + for env_var in ( + "UV_BIN", + "UV_CURRENT_TOOLCHAIN", + "UV_RULES_PYTHON_BIN", + "UV_RULES_PYTHON_UV", + ): + with self.subTest(env_var=env_var): + uv_bin_path = root / os.environ[env_var] + result = subprocess.run( + [uv_bin_path, "--python-fetch", "manual", "--help"], + capture_output=True, + text=True, + check=True, + ) + self.assertIn("Usage: uv [OPTIONS] ", result.stdout) + if __name__ == "__main__": unittest.main() From 4333c550275d657e4d152c870a571c2673c66620 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Tue, 27 Oct 2026 21:37:16 -0700 Subject: [PATCH 2/5] feat(uv): expose $(UV) make variable and fix Windows help test 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. --- docs/api/rules_python/python/uv/bin/index.md | 5 +++++ docs/api/rules_python/python/uv/index.md | 18 +++++++++++++++++- news/uv-bin-target.added.md | 5 +++-- python/uv/private/current_toolchain.bzl | 1 + tests/uv/toolchain/BUILD.bazel | 2 +- tests/uv/toolchain/uv_help_test.py | 6 ++++-- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/docs/api/rules_python/python/uv/bin/index.md b/docs/api/rules_python/python/uv/bin/index.md index 365389df46..fbe0ea238c 100644 --- a/docs/api/rules_python/python/uv/bin/index.md +++ b/docs/api/rules_python/python/uv/bin/index.md @@ -5,6 +5,11 @@ # //python/uv/bin +Executable aliases for the configured `uv` binary. These targets can be run +directly with `bazel run` or passed to tools such as +[`bazel_env.bzl`](https://github.com/buildbuddy-io/bazel_env.bzl) (or via +{obj}`//python/uv:current_toolchain` and `$(UV)`). + ::::{bzl:target} bin Alias for {obj}`//python/uv:current_toolchain` to directly run the configured diff --git a/docs/api/rules_python/python/uv/index.md b/docs/api/rules_python/python/uv/index.md index ff5f08f5ff..29e6d2d49f 100644 --- a/docs/api/rules_python/python/uv/index.md +++ b/docs/api/rules_python/python/uv/index.md @@ -8,7 +8,7 @@ ::::{bzl:target} current_toolchain Exposes the resolved `uv` toolchain for the target/execution platform as an -executable target and template variable provider (`$(UV_BIN)`). +executable target and template variable provider (`$(UV)` and `$(UV_BIN)`). Can be run directly with `bazel run`: @@ -16,6 +16,22 @@ Can be run directly with `bazel run`: bazel run @rules_python//python/uv:current_toolchain -- --help ``` +Or integrated with +[`bazel_env.bzl`](https://github.com/buildbuddy-io/bazel_env.bzl) to expose +`uv` on your local `PATH`: + +```bzl +bazel_env( + name = "bazel_env", + toolchains = { + "uv": "@rules_python//python/uv:current_toolchain", + }, + tools = { + "uv": "$(UV)", + }, +) +``` + :::{versionadded} VERSION_NEXT_FEATURE ::: :::: diff --git a/news/uv-bin-target.added.md b/news/uv-bin-target.added.md index 0de9f35eed..d20ecbaca7 100644 --- a/news/uv-bin-target.added.md +++ b/news/uv-bin-target.added.md @@ -1,4 +1,5 @@ (uv) Added `@uv//bin:bin`, {obj}`//python/uv/bin:uv`, {obj}`//python/uv/bin:bin`, and public visibility on -{obj}`//python/uv:current_toolchain` to run the configured `uv` binary directly -(e.g. `bazel run @uv//bin:bin -- --help`). +{obj}`//python/uv:current_toolchain` (along with the `$(UV)` make variable) to +run the configured `uv` binary directly (e.g. +`bazel run @uv//bin:bin -- --help`). diff --git a/python/uv/private/current_toolchain.bzl b/python/uv/private/current_toolchain.bzl index 06559c9aab..43b3a30c55 100644 --- a/python/uv/private/current_toolchain.bzl +++ b/python/uv/private/current_toolchain.bzl @@ -54,6 +54,7 @@ def _current_toolchain_impl(ctx): ) template_variable_info = platform_common.TemplateVariableInfo({ + "UV": symlink_uv_executable.path, "UV_BIN": symlink_uv_executable.path, }) diff --git a/tests/uv/toolchain/BUILD.bazel b/tests/uv/toolchain/BUILD.bazel index 8b7275f1f7..ad0c52f352 100644 --- a/tests/uv/toolchain/BUILD.bazel +++ b/tests/uv/toolchain/BUILD.bazel @@ -3,7 +3,7 @@ load("//python:py_test.bzl", "py_test") genrule( name = "uv_help", outs = ["uv_help.txt"], - cmd = "$(UV_BIN) --python-fetch manual --help >$@", + cmd = 'test "$(UV)" = "$(UV_BIN)" && $(UV) --python-fetch manual --help >$@', toolchains = ["//python/uv:current_toolchain"], ) diff --git a/tests/uv/toolchain/uv_help_test.py b/tests/uv/toolchain/uv_help_test.py index 23558bb770..daad23f323 100755 --- a/tests/uv/toolchain/uv_help_test.py +++ b/tests/uv/toolchain/uv_help_test.py @@ -21,7 +21,7 @@ def test_uv_help(self): uv_help = Path(uv_help_path).read_text() - self.assertIn("Usage: uv [OPTIONS] ", uv_help) + self.assertRegex(uv_help, r"Usage: uv(\.exe)? \[OPTIONS\] ") def test_uv_bin(self): root = runfiles.CreateOrRaise().root() @@ -40,7 +40,9 @@ def test_uv_bin(self): text=True, check=True, ) - self.assertIn("Usage: uv [OPTIONS] ", result.stdout) + self.assertRegex( + result.stdout, r"Usage: uv(\.exe)? \[OPTIONS\] " + ) if __name__ == "__main__": From c73f46495db52a01bbdb0bd6b4a402d66355565d Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Thu, 29 Oct 2026 20:33:01 -0700 Subject: [PATCH 3/5] feat(uv): replace @uv//bin:bin with @uv//:uv alias 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. --- docs/pypi/lock.md | 2 +- news/uv-bin-target.added.md | 4 ++-- python/uv/private/uv.bzl | 4 ++-- python/uv/private/uv_register_toolchains.bzl | 2 +- python/uv/private/uv_toolchains_repo.bzl | 9 +++------ tests/integration/bzlmod_lockfile/MODULE.bazel.lock | 2 +- tests/uv/toolchain/BUILD.bazel | 4 ++-- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/docs/pypi/lock.md b/docs/pypi/lock.md index 4002627c5d..51b5b12e5d 100644 --- a/docs/pypi/lock.md +++ b/docs/pypi/lock.md @@ -96,7 +96,7 @@ Without `version`, the default version specified by `rules_python` is used. See {obj}`uv.configure` for using a mirror, explicit URLs or extra platforms. To run the configured `uv` binary directly, run `bazel run @rules_python//python/uv/bin:uv -- ` (or add -`use_repo(uv, "uv")` and run `bazel run @uv//bin:bin -- `). +`use_repo(uv, "uv")` and run `bazel run @uv//:uv -- `). (uv-workspace-setup)= ##### WORKSPACE diff --git a/news/uv-bin-target.added.md b/news/uv-bin-target.added.md index d20ecbaca7..b990600b75 100644 --- a/news/uv-bin-target.added.md +++ b/news/uv-bin-target.added.md @@ -1,5 +1,5 @@ -(uv) Added `@uv//bin:bin`, {obj}`//python/uv/bin:uv`, +(uv) Added `@uv//:uv`, {obj}`//python/uv/bin:uv`, {obj}`//python/uv/bin:bin`, and public visibility on {obj}`//python/uv:current_toolchain` (along with the `$(UV)` make variable) to run the configured `uv` binary directly (e.g. -`bazel run @uv//bin:bin -- --help`). +`bazel run @uv//:uv -- --help`). diff --git a/python/uv/private/uv.bzl b/python/uv/private/uv.bzl index 20f578cf15..32462c09fb 100644 --- a/python/uv/private/uv.bzl +++ b/python/uv/private/uv.bzl @@ -40,14 +40,14 @@ To run `uv` directly: ```sh bazel run @rules_python//python/uv/bin:uv -- --help # Or, if `use_repo(uv, "uv")` is in MODULE.bazel: -bazel run @uv//bin:bin -- --help +bazel run @uv//:uv -- --help ``` Since this is only for locking the requirements files, it should be always marked as a `dev_dependency`. :::{versionchanged} VERSION_NEXT_FEATURE -Added `@uv//bin:bin` and {obj}`//python/uv/bin:uv` (aliases for +Added `@uv//:uv` and {obj}`//python/uv/bin:uv` (aliases for {obj}`//python/uv:current_toolchain`) to run the configured `uv` binary directly. ::: diff --git a/python/uv/private/uv_register_toolchains.bzl b/python/uv/private/uv_register_toolchains.bzl index 179317964e..558d6d4232 100644 --- a/python/uv/private/uv_register_toolchains.bzl +++ b/python/uv/private/uv_register_toolchains.bzl @@ -140,7 +140,7 @@ def uv_register_toolchains( creates one download repository per `uv` version and platform, and the toolchain hub repository `name` with a `toolchain` for each of them, which it registers as `@{name}//:all`; {obj}`lock` can then be used, and `uv` can - be run directly via `bazel run @{name}//bin:bin -- `. See the + be run directly via `bazel run @{name}//:uv -- `. See the {ref}`WORKSPACE setup guide ` for usage examples. Platforms without an archive in a manifest get no toolchain. The diff --git a/python/uv/private/uv_toolchains_repo.bzl b/python/uv/private/uv_toolchains_repo.bzl index 9ce485b36b..2e62ad9292 100644 --- a/python/uv/private/uv_toolchains_repo.bzl +++ b/python/uv/private/uv_toolchains_repo.bzl @@ -19,15 +19,13 @@ load("//python/private:text_util.bzl", "render") _TEMPLATE = """\ load("@rules_python//python/uv/private:toolchains_hub.bzl", "toolchains_hub") -{} -""" - -_BIN_BUILD_TEMPLATE = """\ alias( - name = "bin", + name = "uv", actual = "@rules_python//python/uv:current_toolchain", visibility = ["//visibility:public"], ) + +{} """ def _non_empty(d): @@ -53,7 +51,6 @@ def _toolchains_repo_impl(repository_ctx): ), ) repository_ctx.file("BUILD.bazel", contents) - repository_ctx.file("bin/BUILD.bazel", _BIN_BUILD_TEMPLATE) uv_toolchains_repo = repository_rule( _toolchains_repo_impl, diff --git a/tests/integration/bzlmod_lockfile/MODULE.bazel.lock b/tests/integration/bzlmod_lockfile/MODULE.bazel.lock index 1947df0ea0..f2849f4594 100644 --- a/tests/integration/bzlmod_lockfile/MODULE.bazel.lock +++ b/tests/integration/bzlmod_lockfile/MODULE.bazel.lock @@ -259,7 +259,7 @@ }, "@@rules_python+//python/uv:uv.bzl%uv": { "general": { - "bzlTransitiveDigest": "8ltBqOZd6XrCh2wotsEx0rcRFf6JQORpaK6Pu2/0LYk=", + "bzlTransitiveDigest": "wQHhpqOkC72inE+2jHKImemj6oOnGwbZY66g+HM79aU=", "usagesDigest": "UgEeJTkNLce2eABymcbLBebdHpF0D8qrT6A6PSESotA=", "recordedInputs": [ "REPO_MAPPING:rules_python+,bazel_tools bazel_tools", diff --git a/tests/uv/toolchain/BUILD.bazel b/tests/uv/toolchain/BUILD.bazel index ad0c52f352..819b4974e2 100644 --- a/tests/uv/toolchain/BUILD.bazel +++ b/tests/uv/toolchain/BUILD.bazel @@ -15,11 +15,11 @@ py_test( "//python/uv:current_toolchain", "//python/uv/bin", "//python/uv/bin:uv", - "@uv//bin", + "@uv", ], env = { "DATA": "$(rlocationpath :uv_help)", - "UV_BIN": "$(rlocationpath @uv//bin:bin)", + "UV_BIN": "$(rlocationpath @uv//:uv)", "UV_CURRENT_TOOLCHAIN": "$(rlocationpath //python/uv:current_toolchain)", "UV_RULES_PYTHON_BIN": "$(rlocationpath //python/uv/bin:bin)", "UV_RULES_PYTHON_UV": "$(rlocationpath //python/uv/bin:uv)", From 267a7fd35f1d059a9a417820cf910b5ac9660568 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Thu, 29 Oct 2026 23:15:35 -0700 Subject: [PATCH 4/5] refactor(uv): remove //python/uv/bin:bin alias 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. --- docs/api/rules_python/python/uv/bin/index.md | 15 +-------------- news/uv-bin-target.added.md | 7 ++++--- python/uv/bin/BUILD.bazel | 7 ------- tests/uv/toolchain/BUILD.bazel | 2 -- tests/uv/toolchain/uv_help_test.py | 1 - 5 files changed, 5 insertions(+), 27 deletions(-) diff --git a/docs/api/rules_python/python/uv/bin/index.md b/docs/api/rules_python/python/uv/bin/index.md index fbe0ea238c..cb3a914c87 100644 --- a/docs/api/rules_python/python/uv/bin/index.md +++ b/docs/api/rules_python/python/uv/bin/index.md @@ -5,24 +5,11 @@ # //python/uv/bin -Executable aliases for the configured `uv` binary. These targets can be run +Executable alias for the configured `uv` binary. This target can be run directly with `bazel run` or passed to tools such as [`bazel_env.bzl`](https://github.com/buildbuddy-io/bazel_env.bzl) (or via {obj}`//python/uv:current_toolchain` and `$(UV)`). -::::{bzl:target} bin - -Alias for {obj}`//python/uv:current_toolchain` to directly run the configured -`uv` binary: - -```sh -bazel run @rules_python//python/uv/bin -- --help -``` - -:::{versionadded} VERSION_NEXT_FEATURE -::: -:::: - ::::{bzl:target} uv Alias for {obj}`//python/uv:current_toolchain` to directly run the configured diff --git a/news/uv-bin-target.added.md b/news/uv-bin-target.added.md index b990600b75..c3142dc0fe 100644 --- a/news/uv-bin-target.added.md +++ b/news/uv-bin-target.added.md @@ -1,5 +1,6 @@ -(uv) Added `@uv//:uv`, {obj}`//python/uv/bin:uv`, -{obj}`//python/uv/bin:bin`, and public visibility on +(uv) Added `@uv//:uv`, {obj}`//python/uv/bin:uv`, and public visibility on {obj}`//python/uv:current_toolchain` (along with the `$(UV)` make variable) to run the configured `uv` binary directly (e.g. -`bazel run @uv//:uv -- --help`). +`bazel run @rules_python//python/uv/bin:uv -- --help` or +`bazel run @uv -- --help`) +([#4371](https://github.com/bazel-contrib/rules_python/pull/4371)). diff --git a/python/uv/bin/BUILD.bazel b/python/uv/bin/BUILD.bazel index ed6b4dcb01..e357c70545 100644 --- a/python/uv/bin/BUILD.bazel +++ b/python/uv/bin/BUILD.bazel @@ -6,13 +6,6 @@ distribution_filegroup( name = "distribution", ) -alias( - name = "bin", - actual = "//python/uv:current_toolchain", - tags = ["manual"], - visibility = ["//visibility:public"], -) - alias( name = "uv", actual = "//python/uv:current_toolchain", diff --git a/tests/uv/toolchain/BUILD.bazel b/tests/uv/toolchain/BUILD.bazel index 819b4974e2..21f6d2ac15 100644 --- a/tests/uv/toolchain/BUILD.bazel +++ b/tests/uv/toolchain/BUILD.bazel @@ -13,7 +13,6 @@ py_test( data = [ ":uv_help", "//python/uv:current_toolchain", - "//python/uv/bin", "//python/uv/bin:uv", "@uv", ], @@ -21,7 +20,6 @@ py_test( "DATA": "$(rlocationpath :uv_help)", "UV_BIN": "$(rlocationpath @uv//:uv)", "UV_CURRENT_TOOLCHAIN": "$(rlocationpath //python/uv:current_toolchain)", - "UV_RULES_PYTHON_BIN": "$(rlocationpath //python/uv/bin:bin)", "UV_RULES_PYTHON_UV": "$(rlocationpath //python/uv/bin:uv)", }, deps = ["//python/runfiles"], diff --git a/tests/uv/toolchain/uv_help_test.py b/tests/uv/toolchain/uv_help_test.py index daad23f323..eed10e7470 100755 --- a/tests/uv/toolchain/uv_help_test.py +++ b/tests/uv/toolchain/uv_help_test.py @@ -29,7 +29,6 @@ def test_uv_bin(self): for env_var in ( "UV_BIN", "UV_CURRENT_TOOLCHAIN", - "UV_RULES_PYTHON_BIN", "UV_RULES_PYTHON_UV", ): with self.subTest(env_var=env_var): From ecd4db4e37541a6e0a1089c930ea7efeea4886a8 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 30 Oct 2026 00:21:23 -0700 Subject: [PATCH 5/5] docs(uv): mention aliases in current_toolchain target doc 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. --- docs/api/rules_python/python/uv/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api/rules_python/python/uv/index.md b/docs/api/rules_python/python/uv/index.md index 29e6d2d49f..652368944c 100644 --- a/docs/api/rules_python/python/uv/index.md +++ b/docs/api/rules_python/python/uv/index.md @@ -9,6 +9,8 @@ Exposes the resolved `uv` toolchain for the target/execution platform as an executable target and template variable provider (`$(UV)` and `$(UV_BIN)`). +Shorter aliases for this target are also available at +{obj}`//python/uv/bin:uv` and `@uv//:uv`. Can be run directly with `bazel run`: