churchyard / rpms / python3

Forked from rpms/python3 3 years ago
Clone

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

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