Python Rules for Bazel
rules_python
is the home for 4 major components with varying maturity levels.
The Bazel community maintains this repository. Neither Google nor the Bazel team provides support for the code. However, this repository is part of the test suite used to vet new Bazel releases. See How to contribute for information on our development workflow.
Examples
This documentation is an example of sphinxdocs
rules and the rest of the
components have examples in the examples directory.
Migrating from the bundled rules
The core rules are currently available in Bazel as built-in symbols, but this
form is deprecated. Instead, you should depend on rules_python in your
WORKSPACE
or MODULE.bazel
file and load the Python rules from
@rules_python//python:<name>.bzl
or load paths described in the API documentation.
A buildifier
fix is available to automatically migrate BUILD
and .bzl
files to add the
appropriate load()
statements and rewrite uses of native.py_*
.
# Also consider using the -r flag to modify an entire workspace.
buildifier --lint=fix --warnings=native-py <files>
Currently, the WORKSPACE
file needs to be updated manually as per
Getting started.
Note that Starlark-defined bundled symbols underneath
@bazel_tools//tools/python
are also deprecated. These are not yet rewritten
by buildifier.
Migrating to bzlmod
See Bzlmod support for any behaviour differences between
bzlmod
and WORKSPACE
.