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

60a36f2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ec995d8
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
42a4f96
Date: Fri, 19 Jun 2020 16:18:39 +0200
ec995d8
Subject: [PATCH] 00328: Restore pyc to TIMESTAMP invalidation mode as default
ec995d8
 in rpmbuild
ec995d8
ec995d8
Since Fedora 31, the $SOURCE_DATE_EPOCH is set in rpmbuild to the latest
ec995d8
%changelog date. This makes Python default to the CHECKED_HASH pyc
ec995d8
invalidation mode, bringing more reproducible builds traded for an import
ec995d8
performance decrease. To avoid that, we don't default to CHECKED_HASH
ec995d8
when $RPM_BUILD_ROOT is set (i.e. when we are building RPM packages).
ec995d8
---
ec995d8
 Lib/py_compile.py           | 3 ++-
ec995d8
 Lib/test/test_py_compile.py | 2 ++
ec995d8
 2 files changed, 4 insertions(+), 1 deletion(-)
ec995d8
ec995d8
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
42a4f96
index 8e9dd57a54..5e9a16a203 100644
ec995d8
--- a/Lib/py_compile.py
ec995d8
+++ b/Lib/py_compile.py
ec995d8
@@ -70,7 +70,8 @@ class PycInvalidationMode(enum.Enum):
ec995d8
 
ec995d8
 
ec995d8
 def _get_default_invalidation_mode():
ec995d8
-    if os.environ.get('SOURCE_DATE_EPOCH'):
ec995d8
+    if (os.environ.get('SOURCE_DATE_EPOCH') and not
ec995d8
+            os.environ.get('RPM_BUILD_ROOT')):
ec995d8
         return PycInvalidationMode.CHECKED_HASH
ec995d8
     else:
ec995d8
         return PycInvalidationMode.TIMESTAMP
ec995d8
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
42a4f96
index df45764f04..a0afd878d8 100644
ec995d8
--- a/Lib/test/test_py_compile.py
ec995d8
+++ b/Lib/test/test_py_compile.py
ec995d8
@@ -17,6 +17,7 @@ def without_source_date_epoch(fxn):
ec995d8
     def wrapper(*args, **kwargs):
ec995d8
         with support.EnvironmentVarGuard() as env:
ec995d8
             env.unset('SOURCE_DATE_EPOCH')
ec995d8
+            env.unset('RPM_BUILD_ROOT')
ec995d8
             return fxn(*args, **kwargs)
ec995d8
     return wrapper
ec995d8
 
ec995d8
@@ -27,6 +28,7 @@ def with_source_date_epoch(fxn):
ec995d8
     def wrapper(*args, **kwargs):
ec995d8
         with support.EnvironmentVarGuard() as env:
ec995d8
             env['SOURCE_DATE_EPOCH'] = '123456789'
ec995d8
+            env.unset('RPM_BUILD_ROOT')
ec995d8
             return fxn(*args, **kwargs)
ec995d8
     return wrapper
ec995d8