Skip to content

Commit ae64a75

Browse files
committed
Support a SOURCE_DATE_EPOCH prior to 1980
1 parent f16441f commit ae64a75

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

backend/src/hatchling/builders/wheel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def __init__(self, project_id: str, *, reproducible: bool) -> None:
8888
def get_reproducible_time_tuple() -> TIME_TUPLE:
8989
from datetime import datetime, timezone
9090

91-
d = datetime.fromtimestamp(get_reproducible_timestamp(), timezone.utc)
91+
# `zipfile.ZipInfo` does not support timestamps before 1980
92+
min_ts = datetime(1980, 1, 1, tzinfo=timezone.utc).timestamp()
93+
d = datetime.fromtimestamp(max(get_reproducible_timestamp(), min_ts), timezone.utc)
9294
return d.year, d.month, d.day, d.hour, d.minute, d.second
9395

9496
def add_file(self, included_file: IncludedFile) -> tuple[str, str, str]:

tests/backend/builders/test_wheel.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,14 @@ def test_default_auto_detection(self, hatch, helpers, temp_dir, config_file):
786786
zip_info = zip_archive.getinfo(f"{metadata_directory}/WHEEL")
787787
assert zip_info.date_time == (2020, 2, 2, 0, 0, 0)
788788

789-
def test_default_reproducible_timestamp(self, hatch, helpers, temp_dir, config_file):
789+
@pytest.mark.parametrize(
790+
("epoch", "expected_date_time"),
791+
[
792+
("0", (1980, 1, 1, 0, 0, 0)),
793+
("1580601700", (2020, 2, 2, 0, 1, 40)),
794+
],
795+
)
796+
def test_default_reproducible_timestamp(self, hatch, helpers, temp_dir, config_file, epoch, expected_date_time):
790797
config_file.model.template.plugins["default"]["src-layout"] = False
791798
config_file.save()
792799

0 commit comments

Comments
 (0)