Description
🐞 bug report
Description
The _FindPythonRunfilesRoot()
function in the bazel-runfiles
Python module, presumes that the code resides four levels below the runfiles directory. This is not always going to be the case - for example, when rules_pycross
installs the module via pypi
it will typically end up five levels below. Other situations would probably result in two or three levels (which means that checks will pass in cases when they should not).
🔬 Minimal Reproduction
$ cd tmp
$ mkdir -p a.runfiles/pypi/_lock/bazel-runfiles@1.3.0/site-packages
$ pip install --target a.runfiles/pypi/_lock/bazel-runfiles@1.3.0/site-packages bazel-runfiles
$ echo "a,b,c" > a.runfiles/_repo_mapping
$ mkdir -p a.runfiles/_main/b
$ echo 'import runfiles; r = runfiles.Runfiles.Create(); path = r.Rlocation("_main/b/c.txt"); print(path);' > a.runfiles/_main/b/c.py
$ RUNFILES_DIR=$(pwd)/a.runfiles PYTHONPATH=$(pwd)/a.runfiles/pypi/_lock/bazel-runfiles@1.3.0/site-packages/runfiles python3.11 a.runfiles/_main/b/c.py
Traceback (most recent call last):
File "/home/xyz/tmp/runfiles/a.runfiles/_main/b/c.py", line 1, in <module>
import runfiles; r = runfiles.Runfiles.Create(); path = r.Rlocation("_main/b/c.txt"); print(path);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/xyz/tmp/runfiles/a.runfiles/pypi/_lock/bazel-runfiles@1.3.0/site-packages/runfiles/runfiles.py", line 186, in Rlocation
source_repo = self.CurrentRepository(frame=2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/xyz/tmp/runfiles/a.runfiles/pypi/_lock/bazel-runfiles@1.3.0/site-packages/runfiles/runfiles.py", line 275, in CurrentRepository
raise ValueError(
ValueError: /home/xyz/tmp/runfiles/a.runfiles/_main/b/c.py does not lie under the runfiles root /home/xyz/tmp/runfiles/a.runfiles/pypi/_lock
Note that the Python version needs to be 3.11 or higher (there's a separate case that excludes <= 3.10).
🔥 Exception or Error
Attempts to use Rlocation()
fail with ValueError
exceptions:
ValueError: /var/lib/worker/work/24/exec/bazel-out/k8-fastbuild/bin/tools/oci/unit_tests.runfiles/_main/tools/oci/unit_tests.py does not lie under the runfiles root /var/lib/worker/work/24/exec/bazel-out/k8-fastbuild/bin/tools/oci/unit_tests.runfiles/rules_pycross~~lock_repos~pypi/_lock
Metadata
Metadata
Assignees
Labels
No labels