Uses PYTHONPYCACHEPREFIX
to control where __pycache__
goes
#340
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.
Summary
Python 3.x will precompile bytecode artifacts (
*.pyc
files) when these libraries are loaded. These files appear within__pycache__
directories alongside their source code. For libraries provided by the stdlib, these directories will be created or updated within thecpython
layer since the source is located there. Ultimately, this means that loading Python code will result in the interpreter modifying thecpython
layer after it has been created, thus creating non-reproducible builds.There are a couple of options to prevent this layer modification from happening:
PYTHONDONTWRITEBYTECODE
which will ensure these artifacts are never generated.PYTHONPYCACHEPREFIX
which will control where these artifacts appear on the filesystem.I've chosen to set
PYTHONPYCACHEPREFIX
as it still allows any benefit these files may provide while ensuring we aren't inadvertently modifying thecpython
layer.Additionally, I've changed the level at which we apply the
PYTHONPATH
environment variable toDefault
to align with RFC0019.Use Cases
Resolves #317
Checklist