blob: 0a9c70f93fd7326bddcde33e7e71b15df555774b [file] [log] [blame] [view]
Richard Levasseur327b4e32023-10-19 11:03:01 -07001# Python Rules for Bazel
Richard Levasseurede4fd42023-10-17 13:17:34 -07002
Richard Levasseur327b4e32023-10-19 11:03:01 -07003rules_python is the home of the core Python rules -- `py_library`,
4`py_binary`, `py_test`, `py_proto_library`, and related symbols that provide the basis for Python
5support in Bazel. It also contains package installation rules for integrating with PyPI and other indices.
6
7Documentation for rules_python lives here and in the
8[Bazel Build Encyclopedia](https://docs.bazel.build/versions/master/be/python.html).
9
10Examples are in the {gh-path}`examples` directory.
11
12Currently, the core rules build into the Bazel binary, and the symbols in this
13repository are simple aliases. However, we are migrating the rules to Starlark and removing them from the Bazel binary. Therefore, the future-proof way to depend on Python rules is via this repository. See
14{ref}`Migrating from the Bundled Rules` below.
15
16The core rules are stable. Their implementation in Bazel is subject to Bazel's
17[backward compatibility policy](https://docs.bazel.build/versions/master/backward-compatibility.html).
18Once migrated to rules_python, they may evolve at a different
19rate, but this repository will still follow [semantic versioning](https://semver.org).
20
21The 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
22{gh-path}`How to contribute <CONTRIBUTING.md>` for information on our development workflow.
23
24## Bzlmod support
25
26- Status: Beta
27- Full Feature Parity: No
28
29See {gh-path}`Bzlmod support <BZLMOD_SUPPORT.md>` for more details
30
31## Migrating from the bundled rules
32
33The core rules are currently available in Bazel as built-in symbols, but this
34form is deprecated. Instead, you should depend on rules_python in your
35`WORKSPACE` file and load the Python rules from
36`@rules_python//python:defs.bzl`.
37
38A [buildifier](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md)
39fix is available to automatically migrate `BUILD` and `.bzl` files to add the
40appropriate `load()` statements and rewrite uses of `native.py_*`.
41
42```sh
43# Also consider using the -r flag to modify an entire workspace.
44buildifier --lint=fix --warnings=native-py <files>
45```
46
47Currently, the `WORKSPACE` file needs to be updated manually as per [Getting
48started](getting-started).
49
50Note that Starlark-defined bundled symbols underneath
51`@bazel_tools//tools/python` are also deprecated. These are not yet rewritten
52by buildifier.
53
Richard Levasseurede4fd42023-10-17 13:17:34 -070054
55```{toctree}
Richard Levasseurede4fd42023-10-17 13:17:34 -070056:hidden:
57self
Richard Levasseur327b4e32023-10-19 11:03:01 -070058getting-started
59pypi-dependencies
60pip
61coverage
62gazelle
Richard Levasseur847c03f2023-12-14 22:17:53 -080063Contributing <contributing>
Richard Levasseur83e92552023-12-20 22:46:22 -080064support
Richard Levasseur847c03f2023-12-14 22:17:53 -080065Changelog <changelog>
Richard Levasseurede4fd42023-10-17 13:17:34 -070066api/index
Richard Levasseur327b4e32023-10-19 11:03:01 -070067glossary
68genindex
Richard Levasseurede4fd42023-10-17 13:17:34 -070069```