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

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