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

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