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
Python 3.11/3.12 reimplemented prefix discovery as pure Python (Modules/getpath.py).
Its resolvedpath() correctly handles one-level local symlinks but has a bug with
multi-hop relative symlinks that traverse .. components across repository boundaries —
exactly the shape that venv/bin/python produces:
When resolution fails, Python falls back to the PBS compile-time prefix /install,
which does not exist at runtime:
ModuleNotFoundError: No module named 'encodings'
Python 3.9/3.10 used C code (correct). Python 3.13 fixed the bug. Only 3.11 and 3.12
are affected.
Fix
Change pyvenv.cfg's home = key for hermetic (runfiles-based) interpreters from ./bin/ to a relative path that points directly at the PBS bin/ directory:
home = ../../../../aspect_rules_py++python_interpreters+.../bin
This means getpath.py only needs to resolve bin/python → python3.11 — a single
local hop within the PBS package — which works correctly in all Python versions.
System (non-hermetic) interpreters keep home = ./bin unchanged.
Changes
py/private/py_venv/venv.bzl — compute pyvenv_home from the interpreter's
rlocation path for hermetic toolchains; fall back to ./bin for system interpreters
e2e/tools/verify_venv/verify_venv.py — add verify_base_prefix() asserting sys.base_prefix != "/install" and that the stdlib dir exists; call it from verify_all()
e2e/cases/pbs-symlink-prefix-1048/ — regression tests for Python 3.11 and 3.12
OCI layer snapshots updated to reflect the new pyvenv.cfg and verify_venv.py sizes
⏱ Last updated Fri May 29 09:55:30 UTC 2026 · 📊 GitHub API quota 4,316/15,000 (29% used, resets in 14m) 🚀 Powered by Aspect CLI (v2026.22.17) | Aspect Build · X · LinkedIn · YouTube
Measured with hyperfine --warmup 5 --runs 50 on Linux Gate: PR vs HEAD main (threshold: 10%). BCR is shown only as a historical baseline. Build time: cold bazel build //:bench with isolated output base, no disk cache.
sys.path quality
Version
sys.path entries
distinct site-packages roots
duplicate realpaths
BCR 1.11.5 (baseline)
6
1
0
HEAD main
7
2
0
This PR
7
2
0
sys.path quality measured by bench_syspath inside the assembled venv. Duplicate realpaths indicate symlink redundancy; many distinct site-packages roots suggest an inefficient venv layout.
The reason will be displayed to describe this comment to others. Learn more.
Is this test (and associated BUILD) simple enough to just put into py/tests as a unit test?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #1048
Problem: #1048
Python 3.11/3.12 reimplemented prefix discovery as pure Python (
Modules/getpath.py).Its
resolvedpath()correctly handles one-level local symlinks but has a bug withmulti-hop relative symlinks that traverse
..components across repository boundaries —exactly the shape that
venv/bin/pythonproduces:venv/bin/python → ../../../../interpreter_repo/bin/python3.11
When resolution fails, Python falls back to the PBS compile-time prefix
/install,which does not exist at runtime:
ModuleNotFoundError: No module named 'encodings'
Python 3.9/3.10 used C code (correct). Python 3.13 fixed the bug. Only 3.11 and 3.12
are affected.
Fix
Change
pyvenv.cfg'shome =key for hermetic (runfiles-based) interpreters from./bin/to a relative path that points directly at the PBSbin/directory:home = ../../../../aspect_rules_py++python_interpreters+.../bin
This means
getpath.pyonly needs to resolvebin/python → python3.11— a singlelocal hop within the PBS package — which works correctly in all Python versions.
System (non-hermetic) interpreters keep
home = ./binunchanged.Changes
py/private/py_venv/venv.bzl— computepyvenv_homefrom the interpreter'srlocation path for hermetic toolchains; fall back to
./binfor system interpreterse2e/tools/verify_venv/verify_venv.py— addverify_base_prefix()assertingsys.base_prefix != "/install"and that the stdlib dir exists; call it fromverify_all()e2e/cases/pbs-symlink-prefix-1048/— regression tests for Python 3.11 and 3.12pyvenv.cfgandverify_venv.pysizes