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

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