Skip to content

Commit

Permalink
00328: Restore pyc to TIMESTAMP invalidation mode as default in rpmbuild
Browse files Browse the repository at this point in the history
Since Fedora 31, the $SOURCE_DATE_EPOCH is set in rpmbuild to the latest
%changelog date. This makes Python default to the CHECKED_HASH pyc
invalidation mode, bringing more reproducible builds traded for an import
performance decrease. To avoid that, we don't default to CHECKED_HASH
when $RPM_BUILD_ROOT is set (i.e. when we are building RPM packages).

See https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/57#comment-27426
Downstream only: only used when building RPM packages
Ideally, we should talk to upstream and explain why we don't want this
  • Loading branch information
hroncok committed May 31, 2022
1 parent 671df47 commit c8e5f22
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Lib/py_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class PycInvalidationMode(enum.Enum):


def _get_default_invalidation_mode():
if os.environ.get('SOURCE_DATE_EPOCH'):
if (os.environ.get('SOURCE_DATE_EPOCH') and not
os.environ.get('RPM_BUILD_ROOT')):
return PycInvalidationMode.CHECKED_HASH
else:
return PycInvalidationMode.TIMESTAMP
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_py_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def without_source_date_epoch(fxn):
def wrapper(*args, **kwargs):
with os_helper.EnvironmentVarGuard() as env:
env.unset('SOURCE_DATE_EPOCH')
env.unset('RPM_BUILD_ROOT')
return fxn(*args, **kwargs)
return wrapper

Expand All @@ -29,6 +30,7 @@ def with_source_date_epoch(fxn):
def wrapper(*args, **kwargs):
with os_helper.EnvironmentVarGuard() as env:
env['SOURCE_DATE_EPOCH'] = '123456789'
env.unset('RPM_BUILD_ROOT')
return fxn(*args, **kwargs)
return wrapper

Expand Down

0 comments on commit c8e5f22

Please sign in to comment.