1*60517a1eSAndroid Build Coastguard Worker# Python Rules for Bazel 2*60517a1eSAndroid Build Coastguard Worker 3*60517a1eSAndroid Build Coastguard Workerrules_python is the home of the core Python rules -- `py_library`, 4*60517a1eSAndroid Build Coastguard Worker`py_binary`, `py_test`, `py_proto_library`, and related symbols that provide the basis for Python 5*60517a1eSAndroid Build Coastguard Workersupport in Bazel. It also contains package installation rules for integrating with PyPI and other indices. 6*60517a1eSAndroid Build Coastguard Worker 7*60517a1eSAndroid Build Coastguard WorkerDocumentation for rules_python lives here and in the 8*60517a1eSAndroid Build Coastguard Worker[Bazel Build Encyclopedia](https://docs.bazel.build/versions/master/be/python.html). 9*60517a1eSAndroid Build Coastguard Worker 10*60517a1eSAndroid Build Coastguard WorkerExamples are in the {gh-path}`examples` directory. 11*60517a1eSAndroid Build Coastguard Worker 12*60517a1eSAndroid Build Coastguard WorkerCurrently, the core rules build into the Bazel binary, and the symbols in this 13*60517a1eSAndroid Build Coastguard Workerrepository 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*60517a1eSAndroid Build Coastguard Worker{ref}`Migrating from the Bundled Rules` below. 15*60517a1eSAndroid Build Coastguard Worker 16*60517a1eSAndroid Build Coastguard WorkerThe core rules are stable. Their implementation in Bazel is subject to Bazel's 17*60517a1eSAndroid Build Coastguard Worker[backward compatibility policy](https://docs.bazel.build/versions/master/backward-compatibility.html). 18*60517a1eSAndroid Build Coastguard WorkerOnce migrated to rules_python, they may evolve at a different 19*60517a1eSAndroid Build Coastguard Workerrate, but this repository will still follow [semantic versioning](https://semver.org). 20*60517a1eSAndroid Build Coastguard Worker 21*60517a1eSAndroid Build Coastguard WorkerThe 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*60517a1eSAndroid Build Coastguard Worker{gh-path}`How to contribute <CONTRIBUTING.md>` for information on our development workflow. 23*60517a1eSAndroid Build Coastguard Worker 24*60517a1eSAndroid Build Coastguard Worker## Bzlmod support 25*60517a1eSAndroid Build Coastguard Worker 26*60517a1eSAndroid Build Coastguard Worker- Status: Beta 27*60517a1eSAndroid Build Coastguard Worker- Full Feature Parity: No 28*60517a1eSAndroid Build Coastguard Worker 29*60517a1eSAndroid Build Coastguard WorkerSee {gh-path}`Bzlmod support <BZLMOD_SUPPORT.md>` for more details 30*60517a1eSAndroid Build Coastguard Worker 31*60517a1eSAndroid Build Coastguard Worker## Migrating from the bundled rules 32*60517a1eSAndroid Build Coastguard Worker 33*60517a1eSAndroid Build Coastguard WorkerThe core rules are currently available in Bazel as built-in symbols, but this 34*60517a1eSAndroid Build Coastguard Workerform is deprecated. Instead, you should depend on rules_python in your 35*60517a1eSAndroid Build Coastguard Worker`WORKSPACE` file and load the Python rules from 36*60517a1eSAndroid Build Coastguard Worker`@rules_python//python:defs.bzl`. 37*60517a1eSAndroid Build Coastguard Worker 38*60517a1eSAndroid Build Coastguard WorkerA [buildifier](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md) 39*60517a1eSAndroid Build Coastguard Workerfix is available to automatically migrate `BUILD` and `.bzl` files to add the 40*60517a1eSAndroid Build Coastguard Workerappropriate `load()` statements and rewrite uses of `native.py_*`. 41*60517a1eSAndroid Build Coastguard Worker 42*60517a1eSAndroid Build Coastguard Worker```sh 43*60517a1eSAndroid Build Coastguard Worker# Also consider using the -r flag to modify an entire workspace. 44*60517a1eSAndroid Build Coastguard Workerbuildifier --lint=fix --warnings=native-py <files> 45*60517a1eSAndroid Build Coastguard Worker``` 46*60517a1eSAndroid Build Coastguard Worker 47*60517a1eSAndroid Build Coastguard WorkerCurrently, the `WORKSPACE` file needs to be updated manually as per [Getting 48*60517a1eSAndroid Build Coastguard Workerstarted](getting-started). 49*60517a1eSAndroid Build Coastguard Worker 50*60517a1eSAndroid Build Coastguard WorkerNote that Starlark-defined bundled symbols underneath 51*60517a1eSAndroid Build Coastguard Worker`@bazel_tools//tools/python` are also deprecated. These are not yet rewritten 52*60517a1eSAndroid Build Coastguard Workerby buildifier. 53*60517a1eSAndroid Build Coastguard Worker 54*60517a1eSAndroid Build Coastguard Worker 55*60517a1eSAndroid Build Coastguard Worker```{toctree} 56*60517a1eSAndroid Build Coastguard Worker:hidden: 57*60517a1eSAndroid Build Coastguard Workerself 58*60517a1eSAndroid Build Coastguard Workergetting-started 59*60517a1eSAndroid Build Coastguard Workerpypi-dependencies 60*60517a1eSAndroid Build Coastguard WorkerToolchains <toolchains> 61*60517a1eSAndroid Build Coastguard Workerpip 62*60517a1eSAndroid Build Coastguard Workercoverage 63*60517a1eSAndroid Build Coastguard Workerprecompiling 64*60517a1eSAndroid Build Coastguard Workergazelle 65*60517a1eSAndroid Build Coastguard WorkerContributing <contributing> 66*60517a1eSAndroid Build Coastguard Workersupport 67*60517a1eSAndroid Build Coastguard WorkerChangelog <changelog> 68*60517a1eSAndroid Build Coastguard Workerapi/index 69*60517a1eSAndroid Build Coastguard Workerenvironment-variables 70*60517a1eSAndroid Build Coastguard WorkerSphinxdocs <sphinxdocs/index> 71*60517a1eSAndroid Build Coastguard Workerglossary 72*60517a1eSAndroid Build Coastguard Workergenindex 73*60517a1eSAndroid Build Coastguard Worker``` 74