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

[Bug]: interpreter version error when defining a Python toolchain #365

Open
laurentlb opened this issue Jul 10, 2024 · 4 comments
Open

[Bug]: interpreter version error when defining a Python toolchain #365

laurentlb opened this issue Jul 10, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@laurentlb
Copy link

laurentlb commented Jul 10, 2024

What happened?

When trying to define a Python toolchain, I get the error "_MUST_SET_INTERPRETER_VERSION_FLAG" which incorrectly complains about my Bazel version.

Version

Development (host) and target OS/architectures:

Output of bazel --version: 7.2.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 0.7.3

Language(s) and/or frameworks involved:

How to reproduce

$ cat MODULE.bazel
bazel_dep(name = "aspect_rules_py", version = "0.7.3")

register_toolchains("//:my_toolchain")
$ cat BUILD 

load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
load("@aspect_rules_py//py:defs.bzl", "py_binary")

py_binary(
  name = "hello",
  srcs = ["hello.py"],
)

py_runtime(
    name = "python_runtime",
    interpreter_path = "/usr/bin/python3",
    python_version = "PY3",
)

py_runtime_pair(
    name = "my_py_runtime_pair",
    py3_runtime = ":python_runtime",
)

toolchain(
    name = "my_toolchain",
    toolchain = ":my_py_runtime_pair",
    toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)
$ bazel run :hello
ERROR: /Users/laurent/code/repro-python/BUILD:4:10: in py_binary rule //:hello: 
Traceback (most recent call last):
	File "/Users/laurent/output_base/external/aspect_rules_py~/py/private/py_binary.bzl", line 18, column 51, in _py_binary_rule_impl
		py_toolchain = _py_semantics.resolve_toolchain(ctx)
	File "/Users/laurent/output_base/external/aspect_rules_py~/py/private/py_semantics.bzl", line 103, column 13, in _resolve_toolchain
		fail(_MUST_SET_INTERPRETER_VERSION_FLAG)
Error in fail: ERROR: Prior to Bazel 7.x, the python interpreter version must be explicitly provided.

For example in `.bazelrc` with Bazel 6.4, add
        
    common --@aspect_rules_py//py:interpreter_version=3.9.18

Bazel 6.3 and earlier didn't handle the `common` verb for custom flags.
Repeat the flag to avoid discarding the analysis cache:

    build --@aspect_rules_py//py:interpreter_version=3.9.18
    fetch --@aspect_rules_py//py:interpreter_version=3.9.18
    query --@aspect_rules_py//py:interpreter_version=3.9.18
ERROR: /Users/laurent/code/repro-python/BUILD:4:10: Analysis of target '//:hello' failed
ERROR: Analysis of target '//:hello' failed; build aborted
INFO: Elapsed time: 0.152s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target


$ bazel --version 
bazel 7.2.1


### Any other information?

_No response_
@laurentlb laurentlb added the bug Something isn't working label Jul 10, 2024
@njlr
Copy link

njlr commented Aug 27, 2024

Does your .bazelrc have an interpreter version? e.g.

common --@aspect_rules_py//py:interpreter_version=3.9.18

@alexeagle
Copy link
Member

@laurentlb I think the error message was trying to tell you exactly what to do: upgrade to Bazel 7 or use one of the workaround flags.
LMK if that's still not working?

@laurentlb
Copy link
Author

From the original message :

Output of bazel --version: 7.2.1

So I think the error message was wrong.
(I don't fully remember the context of the bug and I haven't tried njlr's suggestion)

@alexeagle
Copy link
Member

Oh I see now. I wonder if it's related to "pystar" bazelbuild/rules_python#1069

@alexeagle alexeagle reopened this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants