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

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