Blame SOURCES/00328-pyc-timestamp-invalidation-mode.patch

d71d1f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d71d1f
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
d71d1f
Date: Thu, 11 Jul 2019 13:44:13 +0200
d71d1f
Subject: [PATCH] 00328: Restore pyc to TIMESTAMP invalidation mode as default
d71d1f
 in rpmbuild
d71d1f
d71d1f
Since Fedora 31, the $SOURCE_DATE_EPOCH is set in rpmbuild to the latest
d71d1f
%changelog date. This makes Python default to the CHECKED_HASH pyc
d71d1f
invalidation mode, bringing more reproducible builds traded for an import
d71d1f
performance decrease. To avoid that, we don't default to CHECKED_HASH
d71d1f
when $RPM_BUILD_ROOT is set (i.e. when we are building RPM packages).
d71d1f
d71d1f
See https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/57#comment-27426
d71d1f
Downstream only: only used when building RPM packages
d71d1f
Ideally, we should talk to upstream and explain why we don't want this
d71d1f
---
d71d1f
 Lib/py_compile.py           | 3 ++-
d71d1f
 Lib/test/test_py_compile.py | 2 ++
d71d1f
 2 files changed, 4 insertions(+), 1 deletion(-)
d71d1f
d71d1f
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
d71d1f
index a81f493731..bba3642bf2 100644
d71d1f
--- a/Lib/py_compile.py
d71d1f
+++ b/Lib/py_compile.py
d71d1f
@@ -70,7 +70,8 @@ class PycInvalidationMode(enum.Enum):
d71d1f
 
d71d1f
 
d71d1f
 def _get_default_invalidation_mode():
d71d1f
-    if os.environ.get('SOURCE_DATE_EPOCH'):
d71d1f
+    if (os.environ.get('SOURCE_DATE_EPOCH') and not
d71d1f
+            os.environ.get('RPM_BUILD_ROOT')):
d71d1f
         return PycInvalidationMode.CHECKED_HASH
d71d1f
     else:
d71d1f
         return PycInvalidationMode.TIMESTAMP
d71d1f
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
d71d1f
index e6791c6916..b2d3dcf7fb 100644
d71d1f
--- a/Lib/test/test_py_compile.py
d71d1f
+++ b/Lib/test/test_py_compile.py
d71d1f
@@ -19,6 +19,7 @@ def without_source_date_epoch(fxn):
d71d1f
     def wrapper(*args, **kwargs):
d71d1f
         with support.EnvironmentVarGuard() as env:
d71d1f
             env.unset('SOURCE_DATE_EPOCH')
d71d1f
+            env.unset('RPM_BUILD_ROOT')
d71d1f
             return fxn(*args, **kwargs)
d71d1f
     return wrapper
d71d1f
 
d71d1f
@@ -29,6 +30,7 @@ def with_source_date_epoch(fxn):
d71d1f
     def wrapper(*args, **kwargs):
d71d1f
         with support.EnvironmentVarGuard() as env:
d71d1f
             env['SOURCE_DATE_EPOCH'] = '123456789'
d71d1f
+            env.unset('RPM_BUILD_ROOT')
d71d1f
             return fxn(*args, **kwargs)
d71d1f
     return wrapper
d71d1f