Repository navigation
Description
Discussed this with @sergiocampama on Friday. He's traveling now so +cc @thomasvl to represent rules_apple.
Bazel 0.27 flips --incompatible_use_python_toolchains. The default Python toolchain is the autodetecting toolchain, which searches for a Python interpreter of the appropriate version (PY2 vs PY3) on PATH. Previously Bazel would default to using python on PATH, regardless of whether or not it was the correct version. Since python is usually PY2, and Bazel Python targets default to PY3 when no python_version attribute is given, this means that the default behavior on Mac and Linux was to analyze a target as PY3 but run it as PY2.
The problem is that most Mac users do not even have Python 3 installed, but they may have upstream dependencies on rules that require Python code (e.g. as a tool). This code can be written to be compatible with both Python 2 and Python 3, as is the case for rules_apple. But unless those targets are also annotated with python_version = "PY2" (which shouldn't otherwise be necessary), they will be analyzed as PY3, and with the toolchain flag, attempt to run using a non-existent Python 3 runtime.
I see the following options:
-
Revert to the old behavior on mac of using whatever
pythonis onPATH, irrespective of whether the target is PY2 or PY3, but only doing so when there's nopython3runtime available. I really don't want to do this, because it's exactly the behavior we're trying to avoid in py_binary doesn't automatically pick a Python runtime matching the requested version #4815, and if we don't break this antipattern now it'll only be harder to break later. -
Add a non-strict version of the autodetecting toolchain that does this fallback, but don't make it the default behavior. This way, users have to opt in to these bad semantics with
--extra_toolchainson the command line orregister_toolchainsin theWORKSPACE. Users could be directed to opt into the non-strict toolchain from the error message in the default strict toolchain.
I think I'll start work on 2 and see if I can get it cherrypicked into 0.27.
Activity
Add a non-strict autodetecting Python toolchain
Fix problems with the non-strict Python toolchain
Add a non-strict autodetecting Python toolchain
Fix problems with the non-strict Python toolchain
Add a non-strict autodetecting Python toolchain
Fix problems with the non-strict Python toolchain
Add a non-strict autodetecting Python toolchain
Fix problems with the non-strict Python toolchain