bpo-29708: Setting SOURCE_DATE_EPOCH forces hash-based .pyc files (GH-5200)

To support reproducible builds, the setting of of SOURCE_DATE_EPOCH triggers the py_compile module -- and by extension, compileall -- to forcibly compile with hash-based .pyc files. This eliminates the possibility of timestamp-based .pyc files which vary between builds.
This commit is contained in:
Bernhard M. Wiedemann 2018-01-24 22:26:18 +01:00 committed by Brett Cannon
parent 6f6eb35f9b
commit ccbe5818af
4 changed files with 22 additions and 1 deletions

View file

@ -112,6 +112,8 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1,
the resulting file would be regular and thus not the same type of file as
it was previously.
"""
if os.environ.get('SOURCE_DATE_EPOCH'):
invalidation_mode = PycInvalidationMode.CHECKED_HASH
if cfile is None:
if optimize >= 0:
optimization = optimize if optimize >= 1 else ''