From ef6b4027e74a8271d89ee44b38e43e273882ef77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Thu, 20 Oct 2022 17:31:51 +0300 Subject: [PATCH] Fixed pre-1980 file timestamps raising ValueError Reference:https://github.com/pypa/wheel/commit/ef6b4027e74a8271d89ee44b38e43e273882ef77 Fixes #418. --- src/wheel/wheelfile.py | 2 ++ tests/test_bdist_wheel.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index b985774..f55fc73 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -30,12 +30,14 @@ WHEEL_INFO_RE = re.compile( r"""^(?P(?P[^\s-]+?)-(?P[^\s-]+?))(-(?P\d[^\s-]*))? -(?P[^\s-]+?)-(?P[^\s-]+?)-(?P\S+)\.whl$""", re.VERBOSE) +MINIMUM_TIMESTAMP = 315532800 # 1980-01-01 00:00:00 UTC def get_zipinfo_datetime(timestamp=None): # Some applications need reproducible .whl files, but they can't do this without forcing # the timestamp of the individual ZipInfo objects. See issue #143. timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', timestamp or time.time())) + timestamp = max(timestamp, MINIMUM_TIMESTAMP) return time.gmtime(timestamp)[0:6] diff --git a/tests/test_bdist_wheel.py b/tests/test_bdist_wheel.py index 5ed9a41..2a4d777 100644 --- a/tests/test_bdist_wheel.py +++ b/tests/test_bdist_wheel.py @@ -154,3 +154,19 @@ def test_wheelfile_line_endings(wheel_paths): wheelfile = next(fn for fn in wf.filelist if fn.filename.endswith('WHEEL')) wheelfile_contents = wf.read(wheelfile) assert b'\r' not in wheelfile_contents + + +def test_unix_epoch_timestamps(dummy_dist, monkeypatch, tmp_path): + monkeypatch.setenv("SOURCE_DATE_EPOCH", "0") + monkeypatch.chdir(dummy_dist) + subprocess.check_call( + [ + sys.executable, + "setup.py", + "bdist_wheel", + "-b", + str(tmp_path), + "--universal", + "--build-number=2", + ] + ) -- 2.33.0