Update bazel-contrib/setup-bazel action to v0.15.0 (#257)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [bazel-contrib/setup-bazel](https://redirect.github.com/bazel-contrib/setup-bazel) | action | minor | `0.14.0` -> `0.15.0` |

---

### Release Notes

<details>
<summary>bazel-contrib/setup-bazel (bazel-contrib/setup-bazel)</summary>

### [`v0.15.0`](https://redirect.github.com/bazel-contrib/setup-bazel/releases/tag/0.15.0)

[Compare Source](https://redirect.github.com/bazel-contrib/setup-bazel/compare/0.14.0...0.15.0)

#### What's Changed

-   Update dependency [@&#8203;actions/cache](https://redirect.github.com/actions/cache) to v4.0.2 by [@&#8203;renovate](https://redirect.github.com/renovate) in [https://github.com/bazel-contrib/setup-bazel/pull/70](https://redirect.github.com/bazel-contrib/setup-bazel/pull/70)
-   Update dependency [@&#8203;actions/cache](https://redirect.github.com/actions/cache) to v4.0.3 by [@&#8203;renovate](https://redirect.github.com/renovate) in [https://github.com/bazel-contrib/setup-bazel/pull/74](https://redirect.github.com/bazel-contrib/setup-bazel/pull/74)
-   Update  actions/cache version to 4.2.2 to resolve caching warning by [@&#8203;yx-altera](https://redirect.github.com/yx-altera) in [https://github.com/bazel-contrib/setup-bazel/pull/79](https://redirect.github.com/bazel-contrib/setup-bazel/pull/79)
-   Revert "Update  actions/cache version to 4.2.2 to resolve caching warning" by [@&#8203;p0deje](https://redirect.github.com/p0deje) in [https://github.com/bazel-contrib/setup-bazel/pull/80](https://redirect.github.com/bazel-contrib/setup-bazel/pull/80)
-   add .exe on windows by [@&#8203;kekxv](https://redirect.github.com/kekxv) in [https://github.com/bazel-contrib/setup-bazel/pull/83](https://redirect.github.com/bazel-contrib/setup-bazel/pull/83)
-   Co-locate Bazel output base with workspace by [@&#8203;p0deje](https://redirect.github.com/p0deje) in [https://github.com/bazel-contrib/setup-bazel/pull/82](https://redirect.github.com/bazel-contrib/setup-bazel/pull/82)

#### New Contributors

-   [@&#8203;yx-altera](https://redirect.github.com/yx-altera) made their first contribution in [https://github.com/bazel-contrib/setup-bazel/pull/79](https://redirect.github.com/bazel-contrib/setup-bazel/pull/79)
-   [@&#8203;kekxv](https://redirect.github.com/kekxv) made their first contribution in [https://github.com/bazel-contrib/setup-bazel/pull/83](https://redirect.github.com/bazel-contrib/setup-bazel/pull/83)

**Full Changelog**: https://github.com/bazel-contrib/setup-bazel/compare/0.14.0...0.15.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "every weekday after 9am before 5pm" in timezone America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

â™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://redirect.github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC4zMy4wIiwidXBkYXRlZEluVmVyIjoiNDAuMzMuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiYXV0b21lcmdlIl19-->
1 file changed
tree: 2b12b4b85e53579a29620fb7ed62e4f8a3004975
  1. .bcr/
  2. .github/
  3. dev/
  4. examples/
  5. uv/
  6. .bazelignore
  7. .bazelrc
  8. .bazelversion
  9. .gitattributes
  10. .gitignore
  11. BUILD.bazel
  12. LICENSE
  13. MODULE.bazel
  14. readme.md
  15. WORKSPACE.bazel
readme.md

rules_uv

Bazel rules to enable use of uv to compile pip requirements and generate virtual envs.

Usage

Installing with bzlmod, add to MODULE.bazel (adjust version as appropriate):

bazel_dep(name = "rules_uv", version = "<version>")

Note: rules_uv requires a Python toolchain to be available. One can be obtained by having rules_python installed using:

bazel_dep(name = "rules_python", version = "<rules_python version>")

pip_compile

Create a requirements.in or pyproject.toml -> requirements.txt compilation target and diff test:

load("@rules_uv//uv:pip.bzl", "pip_compile")

pip_compile(
    name = "generate_requirements_txt",
    requirements_in = "//:requirements.in", # default
    requirements_txt = "//:requirements.txt", # default
)

Ensure both requirements.in and requirements.txt exist (the latter must exist but may be empty).

Run the compilation step with bazel run //:generate_requirements_txt.

This will automatically register a diff test with name [name]_test.

Additionally, you can specify the following optional args:

  • python_platform: the uv pip compile compatible --python-platform value to pass to uv
  • args: override the default arguments passed to uv (--generate-hashes, --emit-index-url and --no-strip-extras)
  • data: pass additional files to be present when generating and testing requirements txt files (see also examples/multiple-inputs)
  • tags: tags to apply to the test target
  • target_compatible_with: restrict targets to running on the specified Bazel platform
  • requirements_overrides: a label for the file that is used to override dependencies (passed to uv via --overrides)

create_venv

Create a virtual environment creation target:

load("@rules_uv//uv:venv.bzl", "create_venv")

create_venv(
    name = "create_venv",
    requirements_txt = "//:requirements.txt", # default
)

Create a virtual environment with default path venv by running bazel run //:create_venv. The generated script accepts a single, optional argument to define the virtual environment path.

The created venv will use the default Python 3 runtime defined in rules_python.

Multi-platform setup

uv supports generating platform-specific requirements files, and rules_uv exposes this configuration, and a multi-platform setup might look like this:

load("@rules_multirun//:defs.bzl", "multirun")
load("@rules_uv//uv:pip.bzl", "pip_compile")
load("@rules_uv//uv:venv.bzl", "create_venv")

pip_compile(
    name = "generate_requirements_linux_txt",
    python_platform = "x86_64-unknown-linux-gnu",
    requirements_txt = "requirements_linux.txt",
)

pip_compile(
    name = "generate_requirements_macos_txt",
    python_platform = "aarch64-apple-darwin",
    requirements_txt = "requirements_macos.txt",
)

multirun(
    name = "generate_requirements_lock",
    commands = [
        ":generate_requirements_linux_txt",
        ":generate_requirements_macos_txt",
    ],
    # Running in a single threaded mode allows consecutive `uv` invocations to benefit
    # from the `uv` cache from the first run.
    jobs = 1,
)

create_venv(
    name = "create_venv",
    requirements_txt = select({
        "@platforms//os:linux": ":requirements_linux.txt",
        "@platforms//os:osx": ":requirements_macos.txt",
    }),
)

This makes use of the excellent rules_multirun.

To match up with rules_python, a bzlmod config will look something like:

pip.parse(
    hub_name = "pip",
    python_version = "3.11",
    requirements_darwin = "//:requirements_macos.txt",
    requirements_linux = "//:requirements_linux.txt",
)