You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suppose something is to be said about the smell that is attempting to set PYTHONPATH for a Bazel target.
Where I run into this problem is with VSCode/PyCharm debuggers which run their own bootstrap code via PYTHONPATH propagation, before running your actual target.
In any case, a simple fix for this is to replace this line, with:
🐞 bug report
Affected Rule
The issue is caused by the rule:
py_binary
/py_test
Is this a regression?
Yes.
Description
The stage-1 bootstrap script runs
python
withPYTHONSAFEPATH=1
, which means that no unsafe paths are preprended to the runtime environment of stage-2.However, the stage-2 script unconditionally deletes
sys.path[0]
. This is harmless most of the time, since the search path that is deleted is/usr/lib/python311.zip
(or similar).But if the target caller attempts to propagate
PYTHONPATH
to the application, the first entry inPYTHONPATH
is incorrectly removed.🔬 Minimal Reproduction
script.py
:BUILD.bazel
:Build and run the target with
PYTHONPATH=foo:bar
, observe thatfoo
is missing fromsys.path
.🌍 Your Environment
Operating System:
Linux AMD64 - CentOS 7, and Debian 11
Output of
bazel version
:Bazel 7.2.1
Rules_python version:
0.36.0 (but present in 0.37.0 too)
The text was updated successfully, but these errors were encountered: