churchyard / rpms / python38

Forked from rpms/python38 5 years ago
Clone
ca6bbeb
From 62c2cdc7a459328e8792f9a029c74f12c4a0abf0 Mon Sep 17 00:00:00 2001
b1d162e
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
b1d162e
Date: Thu, 11 Jul 2019 13:44:13 +0200
b1d162e
Subject: [PATCH] 00328: Restore pyc to TIMESTAMP invalidation mode as default
b1d162e
 in rpmbuild
b1d162e
b1d162e
Since Fedora 31, the $SOURCE_DATE_EPOCH is set in rpmbuild to the latest
b1d162e
%changelog date. This makes Python default to the CHECKED_HASH pyc
b1d162e
invalidation mode, bringing more reproducible builds traded for an import
b1d162e
performance decrease. To avoid that, we don't default to CHECKED_HASH
b1d162e
when $RPM_BUILD_ROOT is set (i.e. when we are building RPM packages).
b1d162e
b1d162e
See https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/57#comment-27426
b1d162e
---
b1d162e
 Lib/py_compile.py           | 3 ++-
b1d162e
 Lib/test/test_py_compile.py | 2 ++
b1d162e
 2 files changed, 4 insertions(+), 1 deletion(-)
b1d162e
b1d162e
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
b1d162e
index 21736896af..310bed5620 100644
b1d162e
--- a/Lib/py_compile.py
b1d162e
+++ b/Lib/py_compile.py
b1d162e
@@ -70,7 +70,8 @@ class PycInvalidationMode(enum.Enum):
b1d162e
 
b1d162e
 
b1d162e
 def _get_default_invalidation_mode():
b1d162e
-    if os.environ.get('SOURCE_DATE_EPOCH'):
b1d162e
+    if (os.environ.get('SOURCE_DATE_EPOCH') and not
b1d162e
+            os.environ.get('RPM_BUILD_ROOT')):
b1d162e
         return PycInvalidationMode.CHECKED_HASH
b1d162e
     else:
b1d162e
         return PycInvalidationMode.TIMESTAMP
b1d162e
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
b1d162e
index d6677ab45f..88059b127e 100644
b1d162e
--- a/Lib/test/test_py_compile.py
b1d162e
+++ b/Lib/test/test_py_compile.py
b1d162e
@@ -17,6 +17,7 @@ def without_source_date_epoch(fxn):
b1d162e
     def wrapper(*args, **kwargs):
b1d162e
         with support.EnvironmentVarGuard() as env:
b1d162e
             env.unset('SOURCE_DATE_EPOCH')
b1d162e
+            env.unset('RPM_BUILD_ROOT')
b1d162e
             return fxn(*args, **kwargs)
b1d162e
     return wrapper
b1d162e
 
b1d162e
@@ -27,6 +28,7 @@ def with_source_date_epoch(fxn):
b1d162e
     def wrapper(*args, **kwargs):
b1d162e
         with support.EnvironmentVarGuard() as env:
b1d162e
             env['SOURCE_DATE_EPOCH'] = '123456789'
b1d162e
+            env.unset('RPM_BUILD_ROOT')
b1d162e
             return fxn(*args, **kwargs)
b1d162e
     return wrapper
b1d162e
 
b1d162e
-- 
b1d162e
2.21.0
b1d162e