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

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