| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Bazel rules for Python that delegate to uv and pyproject.toml instead of reimplementing packaging in Starlark.
Python packaging has grown increasingly capable — uv handles platform wheel selection, dependency resolution, and installation faster than any prior tool. Meanwhile, pyproject.toml has become the universal standard for declaring project metadata and dependencies. The existing Bazel Python ecosystem (rules_python, rules_py, rules_pycross) predates these developments and necessarily reimplemented much of this functionality in Starlark and Rust.
rules_pythonic builds on their foundation but takes a different approach: use standard Python tooling directly. Third-party dependencies stay in pyproject.toml where every Python tool already knows how to find them. uv handles installation and wheel building as Bazel actions. BUILD files declare only first-party relationships. A Python developer who has never used Bazel can read a rules_pythonic BUILD file and understand what it does.
load("@rules_pythonic//pythonic:defs.bzl", "pythonic_devenv", "pythonic_package", "pythonic_test")
pythonic_package(
name = "mypackage",
pyproject = "pyproject.toml",
src_root = "src",
srcs = glob(["src/**/*.py"]),
deps = [":other_package"],
)
# Fast iteration: source directly on PYTHONPATH
pythonic_test(
name = "test_greeting",
srcs = ["tests/test_greeting.py"],
deps = [":mypackage"],
)
# Artifact testing: install the built .whl, catch packaging bugs before deploy
pythonic_test(
name = "test_greeting_wheel",
srcs = ["tests/test_greeting.py"],
deps = [":mypackage.wheel"],
)
# IDE dev environment: `bazel run //:ide` creates a venv with all deps
pythonic_devenv(
name = "ide",
deps = [":mypackage"],
wheels = ["//:all_wheels"],
)Third-party deps (six, torch, pytest) go in pyproject.toml. First-party deps (your own packages) go in BUILD deps. uv handles wheel installation and platform selection at build time. There is no Starlark reimplementation of packaging.
The e2e/smoke directory is a complete working example you can clone and run.
Five rules, one provider:
All loaded from @rules_pythonic//pythonic:defs.bzl.
See docs/DESIGN.md for the full rationale and docs/TECHNICAL_REFERENCE.md for attribute details.
Third-party dependencies flow through two layers:
At build time, install_packages.py runs uv pip install --no-deps --no-index — it installs only what is already in @pypi, never contacts PyPI, and never resolves versions. The pyproject.toml entries are used only for validation: every declared dependency must exist either as a wheel in @pypi or as a first-party dep in BUILD.
When these two layers diverge:
To add a new third-party dependency: add it to pyproject.toml, then regenerate the lockfile (e.g. uv pip compile --all-packages -o requirements.txt). Bazel picks up the change on next build — pip.parse re-evaluates the repo rule when requirements.txt changes.
Requires Bazel 8+. Add to MODULE.bazel:
bazel_dep(name = "rules_pythonic", version = "0.0.2")
bazel_dep(name = "rules_python", version = "1.9.0")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.11")
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pypi",
python_version = "3.11",
requirements_lock = "//:requirements.txt",
)
use_repo(pip, "pypi")Add the wheel filegroup to your root BUILD:
load("@pypi//:requirements.bzl", "all_whl_requirements")
filegroup(
name = "all_wheels",
srcs = all_whl_requirements,
visibility = ["//visibility:public"],
)Configure your uv cache in .bazelrc (both lines required):
build --action_env=UV_CACHE_DIR=/absolute/path/to/uv/cache build --sandbox_writable_path=/absolute/path/to/uv/cache
The cache must be on the same filesystem as Bazel's output base so uv can hardlink wheels instead of copying them. Without this, the build fails with setup instructions.
Apache 2.0
| Back | FazBrowse Home | New Git URL |