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:
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_binarytarget (based on itsdefault_python_versionattr), or by a top-level flag--force_python.Once set, the same mode is used recursively for
py_librarytargets that are transitively in thedepsattr. But targets in thedataattr are reset to unknown, so they can containpy_binarys in a different mode.The mode determines what system python interpreter is used by default (if no
py_runtime/--python_topis given). In the future it may also be used to help select among multiplepy_runtimes.Users can
select()on theforce_pythonflag to condition pieces of the build based on which mode is being used.Bazel validates that python targets marked via
srcs_versionto be only PY2 or only PY3 are built in the expected mode.NB: Current bugs that impact the above description:
The mode change from unknown -> PY2 doesn't actually work. This'll be fixed by the fix for py_library enforces Python 2 for some reason #1446.
The reset over
datadeps isn't yet implemented (Reset the PY2/PY3 mode along data dependencies #6441).The system python version isn't selected correctly for PY3 (py_binary doesn't automatically pick a Python runtime matching the requested version #4815).