Skip to content

Clearly document PY2/PY3 mode #6442

@brandjon

Description

@brandjon

Explain on the python rules page the following info:

  • There's a configuration field for selecting the python major version. It can be PY2, PY3, or unset/unknown.

  • This gets set to PY2 or PY3 when you encounter a py_binary target (based on its default_python_version attr), or by a top-level flag --force_python.

  • Once set, the same mode is used recursively for py_library targets that are transitively in the deps attr. But targets in the data attr are reset to unknown, so they can contain py_binarys in a different mode.

  • The mode determines what system python interpreter is used by default (if no py_runtime / --python_top is given). In the future it may also be used to help select among multiple py_runtimes.

  • Users can select() on the force_python flag to condition pieces of the build based on which mode is being used.

  • Bazel validates that python targets marked via srcs_version to be only PY2 or only PY3 are built in the expected mode.

NB: Current bugs that impact the above description:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions