Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 2 interpreter used for PY3 binaries that are implicit dependencies of rules #7924

Closed
apt-itude opened this issue Apr 2, 2019 · 1 comment
Labels
team-Rules-Python Native rules for Python

Comments

@apt-itude
Copy link
Contributor

Description of the problem

A rule that depends on a py_binary with python_version = "PY3" uses Python 2 interpreter when executing that binary.

Example

BUILD:

load("//:rules.bzl", "touchfile")

touchfile(name = "test")

rules.bzl:

def _touchfile_impl(ctx):
    ctx.actions.run(
        outputs = [ctx.outputs.touchfile],
        executable = ctx.executable._binary,
        arguments = [ctx.outputs.touchfile.path],
    )


touchfile = rule(
    implementation = _touchfile_impl,
    attrs = {
        "_binary": attr.label(
            default = "//src:touch",
            executable = True,
            cfg = "host",
        )
    },
    outputs = {
        "touchfile": "%{name}.touch",
    },
)

src/BUILD:

py_binary(
    name = "touch",
    srcs = ["touch.py"],
    python_version = "PY3",
    srcs_version = "PY3",
    visibility = ["//visibility:public"],
)

Build result:

$ bazel build --incompatible_allow_python_version_transitions :test
INFO: Build option --python_top has changed, discarding analysis cache.
INFO: Analysed target //:test (1 packages loaded, 103 targets configured).
INFO: Found 1 target...
ERROR: /Users/athompson/code/bazel-testing/bazel-py3-binary-as-implicit-rule-dep/src/BUILD:1:1: This target is being built for Python 2 but (transitively) includes Python 3-only sources. You can get diagnostic information about which dependencies introduce this version requirement by running the `find_requirements` aspect. For more info see the documentation for the `srcs_version` attribute.
Target //:test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.481s, Critical Path: 0.01s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  1. git clone https://github.com/apt-itude/bazel-py3-binary-as-implicit-rule-dep.git
  2. cd bazel-py3-binary-as-implicit-rule-dep/
  3. bazel build //:test

What operating system are you running Bazel on?

CentOS Linux release 7.5.1804

What's the output of bazel info release?

release 0.24.0- (@non-git)

If bazel info release returns "development version" or "(@Non-Git)", tell us how you built Bazel.

Installed from vbatts-bazel COPR repository.

Have you found anything relevant by searching the web?

Issue #6443 might be related, just based on the comment that cfg = "host" "prevents switching the PY2/PY3 mode".

@irengrig irengrig added team-Rules-Python Native rules for Python untriaged labels Apr 3, 2019
@brandjon
Copy link
Member

brandjon commented Apr 4, 2019

Yes, this is the generalization of #6443: there's no way to have multiple configurations in host mode, so the plan is to replace host with a host-like mode that allows different configurations. Closing as duplicate.

Note that for non-host configured implicit dependencies, this should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Python Native rules for Python
Projects
None yet
Development

No branches or pull requests

3 participants