Skip to content

fix(toolchains): exclude pycache symlinks from runtime files - #4233

Open
stevendee-recon wants to merge 1 commit into
bazel-contrib:mainfrom
stevendee-recon:pycache-root
Open

stevendee-recon wants to merge 1 commit into
bazel-contrib:mainfrom
stevendee-recon:pycache-root

Conversation

@stevendee-recon

Copy link
Copy Markdown

The runtime's lib/** glob matches the __pycache__ symlinks added in #3661, so they end up in runfiles.

With RULES_PYTHON_PYCACHE_DIR=/dev/null they are symlinks to a character device, and packaging a binary into a tar layer fails (#4198). The glob now excludes __pycache__ and everything under it.

The pyc cache is now keyed on the runtime archive's sha256 rather than a hash of the workspace root. The sources in an archive all share one mtime, so Python's mtime-and-size check can't tell a patch release's sources from the previous one's. The workspace hash didn't keep workspaces apart anyway: the repository contents cache shares one fetched runtime, symlinks included, across workspaces.

The default root stops trying locations that are likely to be shared and instead tries a more reliably user-owned fallback: if XDG_CACHE_HOME is unset, then on non-Windows, $HOME/.cache is used (per XDG). On Windows, %LOCALAPPDATA% is used. (NB. platformdirs would choose rules_python\Cache rather than rules_python_pycache; the current change opts for one directory name everywhere.)

The runtime's `lib/**` glob matches the `__pycache__` symlinks added in
bazel-contrib#3661, so they end up in runfiles.

With `RULES_PYTHON_PYCACHE_DIR=/dev/null` they are symlinks to a
character device, and packaging a binary into a tar layer fails (bazel-contrib#4198).
The glob now excludes `__pycache__` and everything under it.

The pyc cache is now keyed on the runtime archive's sha256 rather than a
hash of the workspace root. The sources in an archive all share one
mtime, so Python's mtime-and-size check can't tell a patch release's
sources from the previous one's. The workspace hash didn't keep
workspaces apart anyway: the repository contents cache shares one
fetched runtime, symlinks included, across workspaces.

The default root stops trying locations that are likely to be shared and
instead tries a more reliably user-owned fallback: if `XDG_CACHE_HOME`
is unset, then on non-Windows, `$HOME/.cache` is used (per [XDG][0]).
On Windows, `%LOCALAPPDATA%` is used. (NB. [`platformdirs`][1] would
choose `rules_python\Cache` rather than `rules_python_pycache`; the
current change opts for one directory name everywhere.)

[0]: https://specifications.freedesktop.org/basedir/latest/#variables
[1]: https://platformdirs.readthedocs.io/en/latest/

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant