Skip to content

py_wheel: always generate zip64-capable wheels #2711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions python/private/py_wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """\
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion tools/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -241,6 +243,7 @@ def __init__(
compress,
outfile=None,
strip_path_prefixes=None,
force_zip64=False,
):
self._name = name
self._version = normalize_pep440(version)
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:])

Expand Down Expand Up @@ -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)
Expand Down