Skip to content

Commit daf1e07

Browse files
fix: support a SOURCE_DATE_EPOCH prior to 1980 (#288)
1 parent 6c339b6 commit daf1e07

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/pdm/backend/wheel.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@
4848
except (ValueError, KeyError):
4949
ZIPINFO_DATE_TIME = (2016, 1, 1, 0, 0, 0)
5050
else:
51-
if _env_date[0] < 1980:
52-
raise ValueError("zipinfo date can't be earlier than 1980")
53-
ZIPINFO_DATE_TIME = _env_date
51+
# `zipfile.ZipInfo` does not support timestamps before 1980
52+
ZIPINFO_DATE_TIME = max(_env_date, (1980, 1, 1, 0, 0, 0))
5453

5554

5655
def _open_for_write(path: str | Path) -> IO[str]:

tests/test_api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from __future__ import annotations
2+
13
import email
4+
import importlib
25
import os
36
import sys
47
import tarfile
@@ -404,6 +407,31 @@ def test_build_wheel_preserve_permission(dist: Path) -> None:
404407
assert filemode & 0o111
405408

406409

410+
@pytest.mark.parametrize("name", ["demo-package"])
411+
@pytest.mark.parametrize(
412+
("epoch", "expected_date_time"),
413+
[
414+
("0", (1980, 1, 1, 0, 0, 0)),
415+
("nan", (2016, 1, 1, 0, 0, 0)),
416+
("1580601700", (2020, 2, 2, 0, 1, 40)),
417+
],
418+
)
419+
def test_build_wheel_respects_source_date_epoch(
420+
monkeypatch: pytest.MonkeyPatch,
421+
dist: Path,
422+
epoch: str,
423+
expected_date_time: tuple[int, ...],
424+
) -> None:
425+
monkeypatch.setenv("SOURCE_DATE_EPOCH", epoch)
426+
from pdm.backend import wheel
427+
428+
importlib.reload(wheel)
429+
wheel_name = api.build_wheel(dist.as_posix())
430+
with zipfile.ZipFile(dist / wheel_name) as zf:
431+
zip_info = zf.getinfo("demo_package-0.1.0.dist-info/WHEEL")
432+
assert zip_info.date_time == expected_date_time
433+
434+
407435
@pytest.mark.usefixtures("scm")
408436
@pytest.mark.parametrize("name", ["demo-using-scm"])
409437
def test_build_wheel_write_version_to_file(fixture_project: Path, dist) -> None:

0 commit comments

Comments
 (0)