Repository navigation
fix(toolchains): write regular __pycache__ files when pyc caching is disabled - #4264
Merged
Merged
Conversation
…disabled When `RULES_PYTHON_PYCACHE_DIR` is `/dev/null` (`NUL` on Windows) or a pycache directory cannot be created, `python_repository` previously symlinked `__pycache__` to `/dev/null`. Those character-device symlinks can behave unexpectedly when read or archived. Instead, return `None` from `_get_pycache_root` when `/dev/null` or `NUL` is specified and create empty regular `__pycache__` files when no pycache root is available, preventing Python from writing local `.pyc` files in the runtime repository. Fixes bazel-contrib#4198
rickeylev
enabled auto-merge
October 14, 2026 06:56
aignas
approved these changes
Oct 14, 2026
aignas
left a comment
Collaborator
There was a problem hiding this comment.
That's a somewhat elegant fix. We create files that glob won't match but also that forces Python to not create any files.
Collaborator
Author
|
Yeah, I'm relatively happy with it. Long term, I'd love to get rid of this problem by preventing Python from findings its underlying repo location in |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When
RULES_PYTHON_PYCACHE_DIRis/dev/null(NULon Windows) or apycache directory cannot be created,
python_repositorypreviouslysymlinked
__pycache__to/dev/null. Those character-device symlinkscan behave unexpectedly when read or archived.
Instead, return
Nonefrom_get_pycache_rootwhen/dev/nullorNULis specified and create empty regular__pycache__files when nopycache root is available, preventing Python from writing local
.pycfiles in the runtime repository.
Fixes #4198