feat: allow registering arbitrary settings for py_binary transitions (#3248)

This implements the ability for users to add additional settings that
py_binary, py_test,
and py_wheel can transition on.

There were three main use cases motivating this feature:
1. Making it easier to have multiple pypi dependency closures and shared
dependencies.
2. Making it easier to override flags for `py_wheel`.
3. Making it easier to have per-target setting of things like
bootstrap_impl, venv
   site packages, etc.

It also adds most of our config settings to the the transition
inputs/outputs for those
rules, which allows users to per-target force particular settings
without having to
use e.g. `with_cfg` to wrap a target with the desired transition
settings. It also
lets use avoid adding dozens of attributes (one per setting); today
there are
about 17 flags.

Under the hood, this works by having a bzlmod api that users can pass
labels to. These
labels are put into a generated bzl file, which the rules load and add
to their
list of transition inputs/outputs. On the target level, the
`config_settings` attribute,
which is a `dict[label, str]`, can be set to change the particular flags
of interest.

Along the way...
* Create a common_labels.bzl file for the shared label strings
* Remove the defunct py_reconfig code in sh_py_run_test.

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
35 files changed
tree: 671b79b6ab94c245c3a7e9253cbd343c6f5bace5
  1. .bazelci/
  2. .bcr/
  3. .ci/
  4. .github/
  5. docs/
  6. examples/
  7. gazelle/
  8. private/
  9. python/
  10. sphinxdocs/
  11. tests/
  12. tools/
  13. .bazelignore
  14. .bazelrc
  15. .bazelversion
  16. .editorconfig
  17. .git-blame-ignore-revs
  18. .gitattributes
  19. .gitignore
  20. .pre-commit-config.yaml
  21. .python-version
  22. .readthedocs.yml
  23. addlicense.sh
  24. AGENTS.md
  25. AUTHORS
  26. BUILD.bazel
  27. BZLMOD_SUPPORT.md
  28. CHANGELOG.md
  29. CONTRIBUTING.md
  30. CONTRIBUTORS
  31. GEMINI.md
  32. internal_dev_deps.bzl
  33. internal_dev_setup.bzl
  34. LICENSE
  35. MODULE.bazel
  36. README.md
  37. RELEASING.md
  38. version.bzl
  39. WORKSPACE
  40. 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.