Skip to content

Commit 4c389c9

Browse files
committed
gh-134261: Don't rely on local time for reproducible builds & tests
1 parent 9983c7d commit 4c389c9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Lib/test/test_zipfile/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ def test_write_with_source_date_epoch(self):
18121812

18131813
with zipfile.ZipFile(TESTFN, "r") as zf:
18141814
zip_info = zf.getinfo("test_source_date_epoch.txt")
1815-
get_time = time.localtime(int(os.environ['SOURCE_DATE_EPOCH']))[:6]
1815+
get_time = time.gmtime(int(os.environ['SOURCE_DATE_EPOCH']))[:6]
18161816
# Compare each element of the date_time tuple
18171817
# Allow for a 1-second difference
18181818
for z_time, g_time in zip(zip_info.date_time, get_time):

Lib/zipfile/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,12 @@ def _for_archive(self, archive):
623623
Return self.
624624
"""
625625
# gh-91279: Set the SOURCE_DATE_EPOCH to a specific timestamp
626-
epoch = os.environ.get('SOURCE_DATE_EPOCH')
627-
get_time = int(epoch) if epoch else time.time()
628-
self.date_time = time.localtime(get_time)[:6]
626+
source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH')
627+
628+
if source_date_epoch:
629+
self.date_time = time.gmtime(int(source_date_epoch))[:6]
630+
else:
631+
self.date_time = time.localtime(time.time())[:6]
629632

630633
self.compress_type = archive.compression
631634
self.compress_level = archive.compresslevel

0 commit comments

Comments
 (0)