From 765c032d06378754b1dae892155b7ed2337e958c Mon Sep 17 00:00:00 2001 From: BlackHat-Dot Date: Sun, 11 Oct 2026 18:15:27 +0530 Subject: [PATCH] BUG: respect mtime=0 when adding files to a wheel --- mesonpy/_wheelfile.py | 2 +- tests/test_wheelfile.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mesonpy/_wheelfile.py b/mesonpy/_wheelfile.py index 5710fb6cb..0d7018632 100644 --- a/mesonpy/_wheelfile.py +++ b/mesonpy/_wheelfile.py @@ -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] diff --git a/tests/test_wheelfile.py b/tests/test_wheelfile.py index ec35a815c..34ad9804f 100644 --- a/tests/test_wheelfile.py +++ b/tests/test_wheelfile.py @@ -6,6 +6,7 @@ import time import zipfile +import pytest import wheel.wheelfile import mesonpy._wheelfile @@ -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'