Skip to content

Commit

Permalink
example: add an example for rules_uv (#354)
Browse files Browse the repository at this point in the history
### Changes are visible to end-users: yes

- Searched for relevant documentation and updated as needed: yes
- Breaking change (forces users to change their own code or config): no
- Suggested release notes appear below: no

### Test plan

- New test cases added
  • Loading branch information
thesayyn authored Jun 24, 2024
1 parent c37e679 commit 88c3adb
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
e2e/
examples/uv_pip_compile
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
test:
uses: bazel-contrib/.github/.github/workflows/bazel.yaml@v6
with:
folders: '[".", "e2e/smoke", "e2e/repository-rule-deps", "e2e/system-interpreter"]'
folders: '[".", "e2e/smoke", "e2e/repository-rule-deps", "e2e/system-interpreter", "examples/uv_pip_compile"]'
# TODO: Build Windows tools and add to toolchain
# TODO(alex): switch the root folder to bzlmod
exclude: |
Expand All @@ -30,7 +30,9 @@ jobs:
{"folder": ".", "bazelversion": "6.4.0"},
{"folder": ".", "bzlmodEnabled": true},
{"folder": "e2e/repository-rule-deps", "bzlmodEnabled": false},
{"folder": "e2e/system-interpreter", "bzlmodEnabled": false}
{"folder": "e2e/system-interpreter", "bzlmodEnabled": false},
{"folder": "examples/uv_pip_compile", "bzlmodEnabled": false},
{"folder": "examples/uv_pip_compile", "bazelversion": "6.4.0"},
]
verify-bcr-patches:
Expand Down
3 changes: 3 additions & 0 deletions examples/uv_pip_compile/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load("@rules_uv//uv:pip.bzl", "pip_compile")

pip_compile(name = "generate_requirements_txt")
18 changes: 18 additions & 0 deletions examples/uv_pip_compile/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"uv pip compile example with py"

bazel_dep(name = "rules_uv", version = "0.14.0", dev_dependency = True)
bazel_dep(name = "rules_python", version = "0.33.2")
bazel_dep(name = "aspect_rules_py", version = "0.7.3", dev_dependency = True)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.9.13")

use_repo(python, "python_3_9_13")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pypi",
python_version = "3.9.13",
requirements_lock = "//:requirements.txt",
)
use_repo(pip, "pypi")
9 changes: 9 additions & 0 deletions examples/uv_pip_compile/app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@aspect_rules_py//py:defs.bzl", "py_binary")

py_binary(
name = "app",
srcs = ["say.py"],
deps = [
"@pypi//cowsay",
],
)
3 changes: 3 additions & 0 deletions examples/uv_pip_compile/app/say.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import cowsay

cowsay.cow('hello py_binary!')
1 change: 1 addition & 0 deletions examples/uv_pip_compile/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cowsay
7 changes: 7 additions & 0 deletions examples/uv_pip_compile/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was autogenerated by uv via the following command:
# bazel run @@//:generate_requirements_txt
--index-url https://pypi.org/simple

cowsay==6.1 \
--hash=sha256:274b1e6fc1b966d53976333eb90ac94cb07a450a700b455af9fbdf882244b30a
# via -r requirements.in

0 comments on commit 88c3adb

Please sign in to comment.