chore: support removal of builtin providers (#2274)

The builtin providers PyInfo, PyRuntimeInfo, and PyCcLinkParamsProvider
are being removed,
which means Bazel throws an error while compiling bzl files if there is
a reference to a
top-level symbol that doesn't exist anymore. For backwards
compatibility, rules_python
consumes/produces these providers, so the symbols are used in various
places.

To fix, use `native.legacy_globals` and Bazel version detection to
conditionally emit
the symbols into `@rules_python_internal`. If they aren't present, they
are reported
as None.

This mimics equivalent functionality in bazel_features; bazel_features
isn't used because
it would require users to update their WORKSPACE to initialize some
dependencies before
rules_python can perform its initialization.

Removal of the builtin symbols is controlled by
`--incompatible_autoload_externally`
(which is in Bazel 8 and has been cherry-picked into earlier version).
If the flag is
enabled with "@rules_python" or "-@rules_python" the providers are
removed from Bazel.

---------

Co-authored-by: Richard Levasseur <rlevasseur@google.com>
15 files changed
tree: 335ade092ad5650f47378efba78be2eaa0f19ffe
  1. .bazelci/
  2. .bcr/
  3. .ci/
  4. .github/
  5. docs/
  6. examples/
  7. gazelle/
  8. python/
  9. sphinxdocs/
  10. tests/
  11. third_party/
  12. tools/
  13. .bazelignore
  14. .bazelrc
  15. .bazelversion
  16. .git-blame-ignore-revs
  17. .gitattributes
  18. .gitignore
  19. .pre-commit-config.yaml
  20. .readthedocs.yml
  21. addlicense.sh
  22. AUTHORS
  23. BUILD.bazel
  24. BZLMOD_SUPPORT.md
  25. CHANGELOG.md
  26. CONTRIBUTING.md
  27. CONTRIBUTORS
  28. DEVELOPING.md
  29. internal_deps.bzl
  30. internal_setup.bzl
  31. LICENSE
  32. MODULE.bazel
  33. README.md
  34. version.bzl
  35. WORKSPACE
  36. WORKSPACE.bzlmod
README.md

Python Rules for Bazel

Build status

Overview

This repository is the home of the core Python rules -- py_library, py_binary, py_test, py_proto_library, and related symbols that provide the basis for Python support in Bazel. It also contains package installation rules for integrating with PyPI and other indices.

Documentation for rules_python is at https://rules-python.readthedocs.io and in the Bazel Build Encyclopedia.

Examples live in the examples directory.

The core rules are stable. Their implementation is subject to Bazel's backward compatibility policy. This repository aims to follow semantic versioning.

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 page for information on our development workflow.

Documentation

For detailed documentation, see https://rules-python.readthedocs.io

Bzlmod support

  • Status: Beta
  • Full Feature Parity: No

See Bzlmod support for more details.