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
2 changes: 1 addition & 1 deletion mesonpy/_wheelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __new__(cls, filename: Path, mode: str = 'r', compression: int = zipfile.ZIP

@staticmethod
def timestamp(mtime: Optional[float] = None) -> Tuple[int, int, int, int, int, int]:
timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', mtime or time.time()))
timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', mtime if mtime is not None else time.time()))
# The ZIP file format does not support timestamps before 1980.
timestamp = max(timestamp, MIN_TIMESTAMP)
return time.gmtime(timestamp)[0:6]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_wheelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import zipfile

import pytest
import wheel.wheelfile

import mesonpy._wheelfile
Expand Down Expand Up @@ -44,6 +45,12 @@ def test_source_date_epoch(tmp_path, monkeypatch):
assert entry.date_time == time.gmtime(epoch)[:6]


@pytest.mark.parametrize('mtime', [0, 283993200, 1668871912])
def test_timestamp(monkeypatch, mtime):
monkeypatch.delenv('SOURCE_DATE_EPOCH', raising=False)
assert mesonpy._wheelfile.WheelFile.timestamp(mtime) == max(time.gmtime(mtime)[:6], (1980, 1, 1, 0, 0, 0))


def test_compression(tmp_path):
# create a wheel and test that everything is compressed
path = tmp_path / 'test-1.0-py3-any-none.whl'
Expand Down
Loading