Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/pdm/backend/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@
except (ValueError, KeyError):
ZIPINFO_DATE_TIME = (2016, 1, 1, 0, 0, 0)
else:
if _env_date[0] < 1980:
raise ValueError("zipinfo date can't be earlier than 1980")
ZIPINFO_DATE_TIME = _env_date
# `zipfile.ZipInfo` does not support timestamps before 1980
ZIPINFO_DATE_TIME = max(_env_date, (1980, 1, 1, 0, 0, 0))


def _open_for_write(path: str | Path) -> IO[str]:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

import email
import importlib
import os
import sys
import tarfile
Expand Down Expand Up @@ -404,6 +407,31 @@ def test_build_wheel_preserve_permission(dist: Path) -> None:
assert filemode & 0o111


@pytest.mark.parametrize("name", ["demo-package"])
@pytest.mark.parametrize(
("epoch", "expected_date_time"),
[
("0", (1980, 1, 1, 0, 0, 0)),
("nan", (2016, 1, 1, 0, 0, 0)),
("1580601700", (2020, 2, 2, 0, 1, 40)),
],
)
def test_build_wheel_respects_source_date_epoch(
monkeypatch: pytest.MonkeyPatch,
dist: Path,
epoch: str,
expected_date_time: tuple[int, ...],
) -> None:
monkeypatch.setenv("SOURCE_DATE_EPOCH", epoch)
from pdm.backend import wheel

importlib.reload(wheel)
wheel_name = api.build_wheel(dist.as_posix())
with zipfile.ZipFile(dist / wheel_name) as zf:
zip_info = zf.getinfo("demo_package-0.1.0.dist-info/WHEEL")
assert zip_info.date_time == expected_date_time


@pytest.mark.usefixtures("scm")
@pytest.mark.parametrize("name", ["demo-using-scm"])
def test_build_wheel_write_version_to_file(fixture_project: Path, dist) -> None:
Expand Down