Skip to content

Improve mac Python 2 toolchain story #8547

Closed

Description

@brandjon

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:

  1. Revert to the old behavior on mac of using whatever python is on PATH, irrespective of whether the target is PY2 or PY3, but only doing so when there's no python3 runtime 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.

  2. 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_toolchains on the command line or register_toolchains in the WORKSPACE. 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

  1. added
    P1
    team-Rules-Python
    on Jun 3, 2019
  2. self-assigned this
    on Jun 3, 2019
  3. added a commit that references this issue on Jun 6, 2019
    65b20f7
  4. added 2 commits that reference this issue on Jun 7, 2019
    1964764
    e59e719
  5. added 2 commits that reference this issue on Jun 18, 2019
    c32de71
    d3091d1
  6. added 2 commits that reference this issue on Jul 15, 2019
    c76c773
    e7896f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1team-Rules-Pythontype: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions