Skip to content

Commit b52f381

Browse files
authored
feat: add py_wheel.compress to control using compression (#2260)
This is useful for development where, for large wheels, a significant portion of the time can be spent compression native binaries Fixes #2240
1 parent 18380a2 commit b52f381

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ A brief description of the categories of changes:
3131
* (whl_filegroup): Provide per default also the `RECORD` file
3232

3333
### Added
34-
* Nothing yet
34+
* (py_wheel) Now supports `compress = (True|False)` to allow disabling
35+
compression to speed up development.
3536

3637
### Removed
3738
* Nothing yet

python/private/py_wheel.bzl

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ _distribution_attrs = {
3434
default = "none",
3535
doc = "Python ABI tag. 'none' for pure-Python wheels.",
3636
),
37+
"compress": attr.bool(
38+
default = True,
39+
doc = "Enable compression of the final archive.",
40+
),
3741
"distribution": attr.string(
3842
mandatory = True,
3943
doc = """\
@@ -466,6 +470,9 @@ def _py_wheel_impl(ctx):
466470
args.add("--description_file", description_file)
467471
other_inputs.append(description_file)
468472

473+
if not ctx.attr.compress:
474+
args.add("--no_compress")
475+
469476
for target, filename in ctx.attr.extra_distinfo_files.items():
470477
target_files = target.files.to_list()
471478
if len(target_files) != 1:

tools/wheelmaker.py

+9
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def __init__(
227227
python_tag,
228228
abi,
229229
platform,
230+
compress,
230231
outfile=None,
231232
strip_path_prefixes=None,
232233
):
@@ -238,6 +239,7 @@ def __init__(
238239
self._platform = platform
239240
self._outfile = outfile
240241
self._strip_path_prefixes = strip_path_prefixes
242+
self._compress = compress
241243
self._wheelname_fragment_distribution_name = escape_filename_distribution_name(
242244
self._name
243245
)
@@ -254,6 +256,7 @@ def __enter__(self):
254256
mode="w",
255257
distribution_prefix=self._distribution_prefix,
256258
strip_path_prefixes=self._strip_path_prefixes,
259+
compression=zipfile.ZIP_DEFLATED if self._compress else zipfile.ZIP_STORED,
257260
)
258261
return self
259262

@@ -388,6 +391,11 @@ def parse_args() -> argparse.Namespace:
388391
output_group.add_argument(
389392
"--out", type=str, default=None, help="Override name of ouptut file"
390393
)
394+
output_group.add_argument(
395+
"--no_compress",
396+
action="store_true",
397+
help="Disable compression of the final archive",
398+
)
391399
output_group.add_argument(
392400
"--name_file",
393401
type=Path,
@@ -516,6 +524,7 @@ def main() -> None:
516524
platform=arguments.platform,
517525
outfile=arguments.out,
518526
strip_path_prefixes=strip_prefixes,
527+
compress=not arguments.no_compress,
519528
) as maker:
520529
for package_filename, real_filename in all_files:
521530
maker.add_file(package_filename, real_filename)

0 commit comments

Comments
 (0)