Skip to content

compile_pip_requirements is not bazel 3.7.0 compatible #522

Closed

Description

@joshua-cannon-techlabs

🐞 bug report

Affected Rule

The issue is caused by the rule: "@rules_python//python:toolchain_type"

Is this a regression?

Yes, the previous version in which this bug was not present was: 0.2.0

Description

@rules_python//python incorrectly passes env into py_binary and py_test rules, causing errors on bazel 3.7.0, where the argument isn't supported.

This is due to the fact that it checks for the existence of propellor_optimize in native which (for me at least) exists in bazel 3.7.0.

🔬 Minimal Reproduction

# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

register_toolchains("//:py_toolchain")

RULES_PYTHON_TAG = "0.3.0"
RULES_PYTHON_SHA256 = "934c9ceb552e84577b0faf1e5a2f0450314985b4d8712b2b70717dc679fdc01b"

http_archive(
    name = "rules_python",
    sha256 = RULES_PYTHON_SHA256,
    url = "https://github.com/bazelbuild/rules_python/releases/download/%s/rules_python-%s.tar.gz" % (RULES_PYTHON_TAG, RULES_PYTHON_TAG),
)
# BUILD
load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair")
package(default_visibility = ["//visibility:public"])

py_runtime(
    name = "local_python38",
    interpreter_path = "/usr/bin/python3.8",
    python_version = "PY3",
)

py_runtime_pair(
    name = "py_runtime_pair",
    py3_runtime = ":local_python38",
)

toolchain(
    name = "py_toolchain",
    # target_compatible_with = <...>,
    toolchain = ":py_runtime_pair",
    toolchain_type = "@rules_python//python:toolchain_type",
)

py_binary(
    name="foo",
    srcs=["foo.py"],
    deps=[],
)
# foo.py
# (empty)

Run bazel build /...


You can verify the hypothesis with:

# test.bzl
def native_print():
    print(dir(native))
    

and amending the BUILD file to have:

load("//:test.bzl", "native_print")

native_print()

You'll see propeller_optimize printed

🔥 Exception or Error


ERROR: ~/.cache/bazel/_bazel_me/5bbdee4d9a0abad6aa7bf833474a12b6/external/rules_python/python/BUILD:151:25: @rules_python//python:requirements.update: no such attribute 'env' in 'py_binary' rule
ERROR: ~.cache/bazel/_bazel_me/5bbdee4d9a0abad6aa7bf833474a12b6/external/rules_python/python/BUILD:151:25: @rules_python//python:requirements_test: no such attribute 'env' in 'py_test' rule
ERROR: /home/joshuacannon/work/test/BUILD:19:10: Target '@rules_python//python:toolchain_type' contains an error and its package is in error and referenced by '//:py_toolchain'
ERROR: While resolving toolchains for target //:foo: invalid registered toolchain '//:py_toolchain': Analysis failed
ERROR: Analysis of target '//:foo' failed; build aborted: Analysis failed

🌍 Your Environment

Operating System:

  
Ubuntu 18.04
  

Output of bazel version:

  
bazel 3.7.0
  

Rules_python version:

  
0.3.0
  

Anything else relevant?

Activity

  1. thundergolfer commented on Sep 12, 2021

    @thundergolfer

    Thanks for the issue report, and the reproduction. I have set up your repro and can confirm the same bug on my end.

    Looking at https://docs.bazel.build/versions/3.7.0/be/c-cpp.html, it appears propeller_optimize first appears in 3.7.0, the release right before 4.X.X.

    Checking dir(native) between 4.0.0 and 3.7.0 (four_point_o - three_point_seven) gives the empty set, unfortunately, so this technique doesn't work.

  2. thundergolfer commented on Sep 12, 2021

    @thundergolfer

    I can't find a way to detect Bazel version outside a workspace rules.

    Semi-related: #526

  3. joshua-cannon-techlabs commented on Sep 13, 2021

    @joshua-cannon-techlabs
    Author

    Surely this can't be the only repo needing to know if the new parameter is supported? 😨
    There's gotta be another repo which does some checking.

    Re #526 : It's an unfortunate reality that the Bazel version bleeds into the internals of rules. We're stuck on 3.7 due to a different set of rules not yet supporting 4.0. I agree it's a testing burden so I would agree with the "we only support version X" policy. It's just a bummer that all tools don't support latest version

  4. groodt commented on Jul 3, 2022

    @groodt
    Contributor

    LTS started with bazel 4.0.0 and the pip rules are not guaranteed to be stable at any version. In light of that I am closing this issue because it is very unlikely to receive attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions