1# Python Rules for Bazel 2 3rules_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 54 55```{toctree} 56:hidden: 57self 58getting-started 59pypi-dependencies 60Toolchains <toolchains> 61pip 62coverage 63precompiling 64gazelle 65Contributing <contributing> 66support 67Changelog <changelog> 68api/index 69environment-variables 70Sphinxdocs <sphinxdocs/index> 71glossary 72genindex 73``` 74