Skip to content

Issues with PYTHONPATH resolution in recent python/rules_python versions #1221

Closed as not planned
@phlax

Description

@phlax

🐞 bug report

Affected Rule

The issue is caused by the rule:

afaict ~any python rules but ive tested or hit the issue with py_binary, py_library

Is this a regression?

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

We had trouble upgrading to 0.19.x versions iirc due to this issue

We have been able to upgrade to 0.20.0 but when upgrading the python version to 3.11 the issue reappears

Description

A clear and concise description of the problem...

Expected paths are not being added to sys.path

🔬 Minimal Reproduction

py_library(
    name = "mylib",
    srcs = ["mylib.py"],
)

py_binary(
    name = "mybin",
    srcs = ["mybin.py"],
    deps = [":mylib"],
)
def myfun():
    print("BOOM!")
from mylib import myfun


def main():
    myfun()


if __name__ == "__main__":
    main()

🔥 Exception or Error

$ bazel run //tools/base:mybin
Starting local Bazel server and connecting to it...
INFO: Invocation ID: 19b6db42-4a15-4858-be40-7cf804c798de
INFO: Analyzed target //tools/base:mybin (126 packages loaded, 3458 targets configured).
INFO: Found 1 target...
Target //tools/base:mybin up-to-date:
  bazel-bin/tools/base/mybin
INFO: Elapsed time: 4.511s, Critical Path: 0.28s
INFO: 4 processes: 4 internal.
INFO: Build completed successfully, 4 total actions
INFO: Running command line: bazel-bin/tools/base/mybin
Traceback (most recent call last):
  File "/home/worker/.cache/bazel/_bazel_worker/f704bab1b165ed1368cb88f9f49e7532/execroot/envoy/bazel-out/k8-fastbuild/bin/tools/base/mybin.runfiles/envoy/tools/base/mybin.py", line 2, in <module>
    from mylib import myfun
ModuleNotFoundError: No module named 'mylib'

🌍 Your Environment

Operating System:

  
Linux
  

Output of bazel version:

  
$ bazel version
Bazelisk version: v1.11.0
Build label: 6.1.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Mar 6 17:09:47 2023 (1678122587)
Build timestamp: 1678122587
Build timestamp as int: 1678122587

  

Rules_python version:

  
0.20.0
  

Anything else relevant?

Python version: 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions