diff options
author | Elvis Pranskevichus <elvis@magic.io> | 2018-10-10 12:43:14 -0400 |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2018-10-10 18:43:14 +0200 |
commit | a6b3ec5b6d4f6387820fccc570eea08b9615620d (patch) | |
tree | 0a4cda67f41ce3e6237f4614c890e73d666e69b5 /Lib/py_compile.py | |
parent | bpo-34926: Make mimetypes.guess_type accept os.PathLike objects (GH-9777) (diff) | |
download | cpython-a6b3ec5b6d4f6387820fccc570eea08b9615620d.tar.gz cpython-a6b3ec5b6d4f6387820fccc570eea08b9615620d.tar.bz2 cpython-a6b3ec5b6d4f6387820fccc570eea08b9615620d.zip |
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.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py index 16dc0a011ff..8e9dd57a544 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 '' |