feat(py): ship the venv's bin/activate in py_image_layer - #1536
xangcastle wants to merge 1 commit into
Conversation
`py_venv` writes `bin/activate` but keeps it in `venv_only`, which only reaches the target's own `DefaultInfo.runfiles`. `py_image_layer` builds the source layer from `VirtualenvInfo.runtime_files`, so an extracted layer had `bin/python`, `pyvenv.cfg` and site-packages but could not be `source`d. `VirtualenvInfo` gains an `activate` field (`File` on the executable `py_venv`, `None` on the internal lib variant) and the layer aspect adds it to the source layer when present. Binaries with `expose_venv = False` are unchanged. The `oci/py_venv_image_layer` listings gain the one row. New e2e `cases/venv-pack`: layers a `py_venv`, extracts them under `$TEST_TMPDIR`, checks no symlink is absolute or dangling, then under `env -i` sources `bin/activate` and asserts `sys.prefix`, `sys.base_prefix`, `sys.executable`, `cowsay.__file__` and every `sys.path` entry resolve inside the relocated tree, and that `deactivate` restores the shell. This is the conda-pack replacement path: tar the runfiles tree, untar on a host with no Python, activate. tar.bzl 0.10.1 `mutate(preserve_symlinks = True)` cannot produce this archive: its awk only classifies readlink results containing `../` as links, so sibling-relative `bin/python3 -> python` stays `type=file` and bsdtar fails on the dangling chain.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✨ Aspect Workflows Tasks📅 Thu Sep 10 00:41:42 UTC 2026 ✅ 44 successful tasks
⏱ Last updated Thu Sep 10 00:54:11 UTC 2026 · 📊 GitHub API quota 1,452/15,000 (10% used, resets in 43m) |
py_binary startup benchmark
sys.path quality
Bazel analysis benchmark
py_image_layer benchmark
|
py_venvwritesbin/activatebut keeps it invenv_only, which only reaches the target's ownDefaultInfo.runfiles.py_image_layerbuilds the source layer fromVirtualenvInfo.runtime_files, so an extracted layer hadbin/python,pyvenv.cfgand site-packages but could not besourced.Change
VirtualenvInfogains anactivatefield: theFileon the executablepy_venv,Noneon the internal lib variant.py_image_layeraspect adds it to the source layer when present. Binaries withexpose_venv = Falseare unchanged.oci/py_venv_image_layerlisting snapshots gain the onebin/activaterow.New e2e:
e2e/cases/venv-packLayers a
py_venv, extracts the tars under$TEST_TMPDIR, checks no symlink is absolute or dangling, then underenv -isourcesbin/activateand assertssys.prefix,sys.base_prefix,sys.executable,cowsay.__file__and everysys.pathentry resolve inside the relocated tree, and thatdeactivaterestores the shell. This is the conda-pack replacement path: tar the runfiles tree, untar on a host with no Python, activate.Why not tar.bzl
tar.bzl 0.10.1
mutate(preserve_symlinks = True)cannot produce this archive: its awk only classifies readlink results containing../as links, so sibling-relativebin/python3 -> pythonstaystype=fileand bsdtar fails on the dangling chain. Documented in the case'sBUILD.bazel.