summaryrefslogtreecommitdiffstats
path: root/Lib/py_compile.py
diff options
context:
space:
mode:
authorElvis Pranskevichus <elvis@magic.io>2018-10-10 16:43:14 (GMT)
committerVictor Stinner <vstinner@redhat.com>2018-10-10 16:43:14 (GMT)
commita6b3ec5b6d4f6387820fccc570eea08b9615620d (patch)
tree0a4cda67f41ce3e6237f4614c890e73d666e69b5 /Lib/py_compile.py
parent7e18deef652a9d413d5dbd19d61073ba7eb5460e (diff)
downloadcpython-a6b3ec5b6d4f6387820fccc570eea08b9615620d.zip
cpython-a6b3ec5b6d4f6387820fccc570eea08b9615620d.tar.gz
cpython-a6b3ec5b6d4f6387820fccc570eea08b9615620d.tar.bz2
bpo-34022: Stop forcing of hash-based invalidation with SOURCE_DATE_EPOCH (GH-9607)
Unconditional forcing of ``CHECKED_HASH`` invalidation was introduced in 3.7.0 in bpo-29708. The change is bad, as it unconditionally overrides *invalidation_mode*, even if it was passed as an explicit argument to ``py_compile.compile()`` or ``compileall``. An environment variable should *never* override an explicit argument to a library function. That change leads to multiple test failures if the ``SOURCE_DATE_EPOCH`` environment variable is set. This changes ``py_compile.compile()`` to only look at ``SOURCE_DATE_EPOCH`` if no explicit *invalidation_mode* was specified. I also made various relevant tests run with explicit control over the value of ``SOURCE_DATE_EPOCH``. While looking at this, I noticed that ``zipimport`` does not work with hash-based .pycs _at all_, though I left the fixes for subsequent commits.
Diffstat (limited to 'Lib/py_compile.py')
-rw-r--r--Lib/py_compile.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
index 16dc0a0..8e9dd57 100644
--- a/Lib/py_compile.py
+++ b/Lib/py_compile.py
@@ -69,8 +69,15 @@ class PycInvalidationMode(enum.Enum):
UNCHECKED_HASH = 3
+def _get_default_invalidation_mode():
+ if os.environ.get('SOURCE_DATE_EPOCH'):
+ return PycInvalidationMode.CHECKED_HASH
+ else:
+ return PycInvalidationMode.TIMESTAMP
+
+
def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1,
- invalidation_mode=PycInvalidationMode.TIMESTAMP):
+ invalidation_mode=None):
"""Byte-compile one Python source file to Python bytecode.
:param file: The source file name.
@@ -112,8 +119,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 invalidation_mode is None:
+ invalidation_mode = _get_default_invalidation_mode()
if cfile is None:
if optimize >= 0:
optimization = optimize if optimize >= 1 else ''