Skip to content

Commit

Permalink
feat: support specifying zipinfo date via env var (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Jan 30, 2023
1 parent 3e34c8a commit e776826
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/143.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support specifying wheel date by `SOURCE_DATE_EPOCH` environment variable.
12 changes: 10 additions & 2 deletions pdm/pep517/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import subprocess
import sys
import tempfile
import time
import tokenize
import zipfile
from base64 import urlsafe_b64encode
Expand All @@ -36,6 +37,14 @@
)

PY_LIMITED_API_PATTERN = r"cp3\d"
try:
_env_date = time.gmtime(int(os.environ["SOURCE_DATE_EPOCH"]))[:6]
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


class RecordEntry(NamedTuple):
Expand All @@ -46,7 +55,6 @@ class RecordEntry(NamedTuple):

class WheelEntry(metaclass=abc.ABCMeta):
# Fix the date time for reproducible builds
date_time = (2016, 1, 1, 0, 0, 0)

def __init__(self, rel_path: str) -> None:
self.rel_path = rel_path
Expand All @@ -56,7 +64,7 @@ def open(self) -> BinaryIO:
pass

def build_zipinfo(self) -> zipfile.ZipInfo:
return zipfile.ZipInfo(self.rel_path, self.date_time)
return zipfile.ZipInfo(self.rel_path, ZIPINFO_DATE_TIME)

def write_to_zip(self, zf: zipfile.ZipFile) -> RecordEntry:
zi = self.build_zipinfo()
Expand Down

0 comments on commit e776826

Please sign in to comment.