From 00765dece20dfbddf1d6bbbb8b73719f0e657cbd Mon Sep 17 00:00:00 2001 From: Tobi Date: Wed, 26 Mar 2025 17:20:51 +0000 Subject: [PATCH 1/3] feat: Add force_zip64 option --- CHANGELOG.md | 1 + python/private/py_wheel.bzl | 6 ++++++ tools/wheelmaker.py | 13 ++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96bf33dbd5..ff01df78fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Unreleased changes template. ### Added * Add support for riscv64 linux platform. * (toolchains) Add python 3.13.2 and 3.12.9 toolchains +* Add force_zip64 option for python wheel creation {#v0-0-0-removed} ### Removed diff --git a/python/private/py_wheel.bzl b/python/private/py_wheel.bzl index c196ca6ad0..ab9c476459 100644 --- a/python/private/py_wheel.bzl +++ b/python/private/py_wheel.bzl @@ -54,6 +54,10 @@ Workspace status keys are expanded using `{NAME}` format, for example: For the available keys, see https://bazel.build/docs/user-manual#workspace-status """, ), + "force_zip64": attr.bool( + default = False, + doc = "Force zip64.", + ), "platform": attr.string( default = "any", doc = """\ @@ -513,6 +517,8 @@ def _py_wheel_impl(ctx): "--data_files", filename + ";" + target_files[0].path, ) + if ctx.attr.force_zip64: + args.add("--force_zip64") ctx.actions.run( mnemonic = "PyWheel", diff --git a/tools/wheelmaker.py b/tools/wheelmaker.py index 23b18eca5f..0de7aec654 100644 --- a/tools/wheelmaker.py +++ b/tools/wheelmaker.py @@ -107,9 +107,11 @@ def __init__( distribution_prefix: str, strip_path_prefixes=None, compression=zipfile.ZIP_DEFLATED, + force_zip64=False, **kwargs, ): self._distribution_prefix = distribution_prefix + self._force_zip64 = force_zip64 self._strip_path_prefixes = strip_path_prefixes or [] # Entries for the RECORD file as (filename, hash, size) tuples. @@ -154,7 +156,7 @@ def arcname_from(name): hash = hashlib.sha256() size = 0 with open(real_filename, "rb") as fsrc: - with self.open(zinfo, "w") as fdst: + with self.open(zinfo, "w", force_zip64=self._force_zip64) as fdst: while True: block = fsrc.read(2**20) if not block: @@ -241,6 +243,7 @@ def __init__( compress, outfile=None, strip_path_prefixes=None, + force_zip64=False, ): self._name = name self._version = normalize_pep440(version) @@ -250,6 +253,7 @@ def __init__( self._platform = platform self._outfile = outfile self._strip_path_prefixes = strip_path_prefixes + self._force_zip64 = force_zip64 self._compress = compress self._wheelname_fragment_distribution_name = escape_filename_distribution_name( self._name @@ -268,6 +272,7 @@ def __enter__(self): distribution_prefix=self._distribution_prefix, strip_path_prefixes=self._strip_path_prefixes, compression=zipfile.ZIP_DEFLATED if self._compress else zipfile.ZIP_STORED, + force_zip64=self._force_zip64, ) return self @@ -478,6 +483,11 @@ def parse_args() -> argparse.Namespace: type=Path, help="Pass in the stamp info file for stamping", ) + output_group.add_argument( + "--force_zip64", + action="store_true", + help="Forces usage of zip64", + ) return parser.parse_args(sys.argv[1:]) @@ -536,6 +546,7 @@ def main() -> None: outfile=arguments.out, strip_path_prefixes=strip_prefixes, compress=not arguments.no_compress, + force_zip64=arguments.force_zip64, ) as maker: for package_filename, real_filename in all_files: maker.add_file(package_filename, real_filename) From bd369341a67c16b09dac610220c530837c27f22c Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 19 Apr 2025 23:26:48 -0700 Subject: [PATCH 2/3] always set forceZip64=True --- tools/wheelmaker.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tools/wheelmaker.py b/tools/wheelmaker.py index 0de7aec654..803e79d190 100644 --- a/tools/wheelmaker.py +++ b/tools/wheelmaker.py @@ -107,11 +107,9 @@ def __init__( distribution_prefix: str, strip_path_prefixes=None, compression=zipfile.ZIP_DEFLATED, - force_zip64=False, **kwargs, ): self._distribution_prefix = distribution_prefix - self._force_zip64 = force_zip64 self._strip_path_prefixes = strip_path_prefixes or [] # Entries for the RECORD file as (filename, hash, size) tuples. @@ -156,7 +154,7 @@ def arcname_from(name): hash = hashlib.sha256() size = 0 with open(real_filename, "rb") as fsrc: - with self.open(zinfo, "w", force_zip64=self._force_zip64) as fdst: + with self.open(zinfo, "w", force_zip64=True) as fdst: while True: block = fsrc.read(2**20) if not block: @@ -243,7 +241,6 @@ def __init__( compress, outfile=None, strip_path_prefixes=None, - force_zip64=False, ): self._name = name self._version = normalize_pep440(version) @@ -253,7 +250,6 @@ def __init__( self._platform = platform self._outfile = outfile self._strip_path_prefixes = strip_path_prefixes - self._force_zip64 = force_zip64 self._compress = compress self._wheelname_fragment_distribution_name = escape_filename_distribution_name( self._name @@ -272,7 +268,6 @@ def __enter__(self): distribution_prefix=self._distribution_prefix, strip_path_prefixes=self._strip_path_prefixes, compression=zipfile.ZIP_DEFLATED if self._compress else zipfile.ZIP_STORED, - force_zip64=self._force_zip64, ) return self @@ -483,11 +478,6 @@ def parse_args() -> argparse.Namespace: type=Path, help="Pass in the stamp info file for stamping", ) - output_group.add_argument( - "--force_zip64", - action="store_true", - help="Forces usage of zip64", - ) return parser.parse_args(sys.argv[1:]) @@ -546,7 +536,6 @@ def main() -> None: outfile=arguments.out, strip_path_prefixes=strip_prefixes, compress=not arguments.no_compress, - force_zip64=arguments.force_zip64, ) as maker: for package_filename, real_filename in all_files: maker.add_file(package_filename, real_filename) From 3e90a1f58b2a458223e741a63ca96b2ea0ecd99d Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 19 Apr 2025 23:27:55 -0700 Subject: [PATCH 3/3] remove passing zip64 as cli --- python/private/py_wheel.bzl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/python/private/py_wheel.bzl b/python/private/py_wheel.bzl index ab9c476459..c196ca6ad0 100644 --- a/python/private/py_wheel.bzl +++ b/python/private/py_wheel.bzl @@ -54,10 +54,6 @@ Workspace status keys are expanded using `{NAME}` format, for example: For the available keys, see https://bazel.build/docs/user-manual#workspace-status """, ), - "force_zip64": attr.bool( - default = False, - doc = "Force zip64.", - ), "platform": attr.string( default = "any", doc = """\ @@ -517,8 +513,6 @@ def _py_wheel_impl(ctx): "--data_files", filename + ";" + target_files[0].path, ) - if ctx.attr.force_zip64: - args.add("--force_zip64") ctx.actions.run( mnemonic = "PyWheel",