From 5379e3e0dcab47872e8bd96d213c80e3447abcaa Mon Sep 17 00:00:00 2001 From: 3pleX-dev Date: Tue, 22 Apr 2025 10:40:38 +0000 Subject: [PATCH] modify the build_wheel method to use consistent timestamps when creating wheel files --- sipbuild/builder.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sipbuild/builder.py b/sipbuild/builder.py index 612bcfc3..b89df7cf 100644 --- a/sipbuild/builder.py +++ b/sipbuild/builder.py @@ -177,7 +177,12 @@ def build_wheel(self, wheel_directory): saved_cwd = os.getcwd() os.chdir(wheel_build_dir) - from zipfile import ZipFile, ZIP_DEFLATED + import time + from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED + + # Ensure reproducible wheel file timestamps + epoch = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) + zip_timestamp = time.gmtime(epoch)[:6] with ZipFile(wheel_path, 'w', compression=ZIP_DEFLATED) as zf: for dirpath, _, filenames in os.walk('.'): @@ -185,7 +190,10 @@ def build_wheel(self, wheel_directory): # This will result in a name with no leading '.'. name = os.path.relpath(os.path.join(dirpath, filename)) - zf.write(name) + zi = ZipInfo(name, zip_timestamp) + + with open(name, 'rb') as f: + zf.writestr(zi, f.read()) os.chdir(saved_cwd)