Skip to content

Commit 245382e

Browse files
BlackHat-Dotdnicolodi
authored andcommitted
BUG: respect mtime=0 when adding files to a wheel
1 parent 9ee393f commit 245382e

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎mesonpy/_wheelfile.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __new__(cls, filename: Path, mode: str = 'r', compression: int = zipfile.ZIP
4242

4343
@staticmethod
4444
def timestamp(mtime: Optional[float] = None) -> Tuple[int, int, int, int, int, int]:
45-
timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', mtime or time.time()))
45+
timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', mtime if mtime is not None else time.time()))
4646
# The ZIP file format does not support timestamps before 1980.
4747
timestamp = max(timestamp, MIN_TIMESTAMP)
4848
return time.gmtime(timestamp)[0:6]

‎tests/test_wheelfile.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
import zipfile
88

9+
import pytest
910
import wheel.wheelfile
1011

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

4647

48+
@pytest.mark.parametrize('mtime', [0, 283993200, 1668871912])
49+
def test_timestamp(monkeypatch, mtime):
50+
monkeypatch.delenv('SOURCE_DATE_EPOCH', raising=False)
51+
assert mesonpy._wheelfile.WheelFile.timestamp(mtime) == max(time.gmtime(mtime)[:6], (1980, 1, 1, 0, 0, 0))
52+
53+
4754
def test_compression(tmp_path):
4855
# create a wheel and test that everything is compressed
4956
path = tmp_path / 'test-1.0-py3-any-none.whl'

0 commit comments

Comments
 (0)