rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

Bazel 7 ignores hermetic interpreter

Open nikonikolov opened this issue 1 year ago β€’ 1 comments

🐞 bug report

Affected Rule

The issue is caused by the rule: `py_binary`

Is this a regression?

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

Description

Bazel 7 falls back to system interpreter instead of hermetic interpreter

πŸ”¬ Minimal Reproduction

WORKSPACE:

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

http_archive(
    name = "rules_python",
    sha256 = "b289b0b023c71b80f26d39476e5e2c3cf72d21cb2759bcf02638ba3cc480e9df",
    strip_prefix = "rules_python-0.32.1",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.32.1/rules_python-0.32.1.tar.gz",
)
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
py_repositories()

python_register_toolchains(
    name = "python_runtime",
    python_version = "3.10",
)

load("@python_runtime//:defs.bzl", python_interpreter = "interpreter")

load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
    name = "pip-build",
    python_interpreter_target = python_interpreter,
    requirements_lock = "//:requirements.txt",
)

load("@pip-build//:requirements.bzl", pip_build_install_deps = "install_deps")

pip_build_install_deps()

BUILD:

load("@pip-build//:requirements.bzl", pip_build = "requirement")
load("@rules_python//python:defs.bzl", "py_binary")

py_binary(
    name = "ipython3",
    srcs = ["ipython3.py"],
    deps = [
        pip_build("ipython"),
    ],
)

requirements.txt

asttokens==2.4.1
decorator==5.1.1
exceptiongroup==1.2.0
executing==2.0.1
ipython==8.18.1
jedi==0.19.1
matplotlib-inline==0.1.6
parso==0.8.4
pexpect==4.9.0
prompt-toolkit==3.0.43
ptyprocess==0.7.0
pure-eval==0.2.2
pygments==2.17.2
six==1.16.0
stack-data==0.6.3
traitlets==5.14.0
wcwidth==0.2.13

ipython3.py:

import re
import sys

from IPython import start_ipython

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(start_ipython())

πŸ”₯ Exception or Error

Running bazel run //:ipython3 drops to a python interpreter with version 3.11.9, which is not the 3.10 version specified in WORKSPACE, but the system version. Running import sys; print(sys.executable) from inside the interactive interpreter prints /usr/bin/python3

🌍 Your Environment

Operating System:

Slackware Linux (-current branch)

Output of bazel version:

  
Build label: 7.1.2
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Sun May 12 20:23:16 2024 (1715545396)
Build timestamp: 1715545396
Build timestamp as int: 1715545396
  

Rules_python version:

  
0.32.1
  

Anything else relevant? The above code works absolutely fine with bazel 6.4.0

nikonikolov avatar May 13 '24 21:05 nikonikolov

I guess the reason is the same as https://github.com/bazelbuild/rules_python/issues/1675.

yoerg avatar May 15 '24 04:05 yoerg

Closing as duplicate, if you have MODULE.bazel consider setting up rules_python with bzlmod. Most of the features (and sometimes more) exist on bzlmod.

aignas avatar Jun 04 '24 01:06 aignas