From 00765dece20dfbddf1d6bbbb8b73719f0e657cbd Mon Sep 17 00:00:00 2001 From: Tobi Date: Wed, 26 Mar 2025 17:20:51 +0000 Subject: [PATCH 1/7] 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/7] 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/7] 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", From 9ab56c256a05ad175fb7464f350ec8fc05026d94 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 2 May 2025 16:56:13 -0700 Subject: [PATCH 4/7] Update hash --- examples/wheel/wheel_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wheel/wheel_test.py b/examples/wheel/wheel_test.py index 43e56cfc17..4a5670d67f 100644 --- a/examples/wheel/wheel_test.py +++ b/examples/wheel/wheel_test.py @@ -346,7 +346,7 @@ def test_custom_package_root_multi_prefix_reverse_order_wheel(self): for line in record_contents.splitlines(): self.assertFalse(line.startswith("/")) self.assertFileSha256Equal( - filename, "9e8c0baa408b829dec691a5e8d3bc040be0bbfcc95c0eee19e1e5ffadea4a059" + filename, "372ef9e11fb79f1952172993718a326b5adda192d94884b54377c34b44394982" ) def test_python_requires_wheel(self): From ed9596024e967ff1031c9de9a87e8d77c7ea86ba Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 2 May 2025 17:03:12 -0700 Subject: [PATCH 5/7] Fix more hashes --- examples/wheel/wheel_test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/wheel/wheel_test.py b/examples/wheel/wheel_test.py index 4a5670d67f..31cfeb0d3b 100644 --- a/examples/wheel/wheel_test.py +++ b/examples/wheel/wheel_test.py @@ -85,7 +85,7 @@ def test_py_library_wheel(self): ], ) self.assertFileSha256Equal( - filename, "a73acae23590c7a8d4365c888c1f12f0399b7af27169ea99fc7a00f402833926" + filename, "ef5afd9f6c3ff569ef7e5b2799d3a2ec9675d029414f341e0abd7254d6b9a25d" ) def test_py_package_wheel(self): @@ -110,7 +110,7 @@ def test_py_package_wheel(self): ], ) self.assertFileSha256Equal( - filename, "a76001500453dbd1d778821dcaba165d56db502c854cef9381dd3f8f89caee11" + filename, "39bec133cf79431e8d057eae550cd91aa9dfbddfedb53d98ebd36e3ade2753d0" ) def test_customized_wheel(self): @@ -206,7 +206,7 @@ def test_customized_wheel(self): second = second.main:s""", ) self.assertFileSha256Equal( - filename, "941c0d79f4ca67cfa0028248bd0606db7fc69953ff9c7c73ac26a3e6d3c23587" + filename, "685f68fc6665f53c9b769fd1ba12cce9937ab7f40ef4e60c82ef2de8653935de" ) def test_filename_escaping(self): @@ -278,7 +278,7 @@ def test_custom_package_root_wheel(self): for line in record_contents.splitlines(): self.assertFalse(line.startswith("/")) self.assertFileSha256Equal( - filename, "7bd959b7efe9e325b30a6559177a1a4f22ac7a68fade310845916276110e9287" + filename, "2fbfc3baaf6fccca0f97d02316b8344507fe6c8136991a66ee5f162235adb19f" ) def test_custom_package_root_multi_prefix_wheel(self): @@ -312,7 +312,7 @@ def test_custom_package_root_multi_prefix_wheel(self): for line in record_contents.splitlines(): self.assertFalse(line.startswith("/")) self.assertFileSha256Equal( - filename, "caf51e22bdcd3c6c766c8903319ce717daeb6caac577d14e16326a8597981854" + filename, "3e67971ca1e8a9ba36a143df7532e641f5661c56235e41d818309316c955ba58" ) def test_custom_package_root_multi_prefix_reverse_order_wheel(self): @@ -371,7 +371,7 @@ def test_python_requires_wheel(self): """, ) self.assertFileSha256Equal( - filename, "b47f3eaf4f9fa4685a58c7415ba1feddd39635ae26c18473504f7d7e62e8ce07" + filename, "10a325ba8f77428b5cfcff6345d508f5eb77c140889eb62490d7382f60d4ebfe" ) def test_python_abi3_binary_wheel(self): From 624e040f1122fff01ae42bcfe606c29fd3f00163 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 2 May 2025 20:13:42 -0700 Subject: [PATCH 6/7] Fix another hash --- examples/wheel/wheel_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wheel/wheel_test.py b/examples/wheel/wheel_test.py index 31cfeb0d3b..7f19ecd9f9 100644 --- a/examples/wheel/wheel_test.py +++ b/examples/wheel/wheel_test.py @@ -436,7 +436,7 @@ def test_rule_creates_directory_and_is_included_in_wheel(self): ], ) self.assertFileSha256Equal( - filename, "d8e874b807e5574bd11a9312c58ce7fe7055afb80412d0d0e7ed21fc9223cd53" + filename, "85e44c43cc19ccae9fe2e1d629230203aa11791bed1f7f68a069fb58d1c93cd2" ) def test_rule_expands_workspace_status_keys_in_wheel_metadata(self): From cf9e3dd4dce4a7aa9d58662d14e8a810dc0e239a Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 2 May 2025 20:15:22 -0700 Subject: [PATCH 7/7] Fix test_publish hash --- examples/wheel/test_publish.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wheel/test_publish.py b/examples/wheel/test_publish.py index e6ec80721b..7665629c19 100644 --- a/examples/wheel/test_publish.py +++ b/examples/wheel/test_publish.py @@ -104,7 +104,7 @@ def test_upload_and_query_simple_api(self):

Links for example-minimal-library

- example_minimal_library-0.0.1-py3-none-any.whl
+ example_minimal_library-0.0.1-py3-none-any.whl
""" self.assertEqual(