Skip to content

Commit df887d6

Browse files
committed
Add attribute for disabling wheel compression
This is useful for development where, for large wheels, a significant portion of the time can be spent compression native binaries Fixes bazel-contrib#2240
1 parent 2d34f6c commit df887d6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def __init__(
102102
filename,
103103
*,
104104
mode,
105+
compression,
105106
distribution_prefix: str,
106107
strip_path_prefixes=None,
107-
compression=zipfile.ZIP_DEFLATED,
108108
**kwargs,
109109
):
110110
self._distribution_prefix = distribution_prefix
@@ -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)