Skip to content

Commit c8dc1ed

Browse files
committed
Enable different compressions in WheelBuilder
1 parent 3764271 commit c8dc1ed

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

setuptools/_wheelbuilder.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
_HASH_ALG = "sha256"
2121
_HASH_BUF_SIZE = 65536
2222
_MINIMUM_TIMESTAMP = 315532800 # 1980-01-01 00:00:00 UTC
23-
_COMPRESSION = ZIP_DEFLATED
23+
_DEFAULT_COMPRESSION = ZIP_DEFLATED
2424
_WHEEL_VERSION = "1.0"
2525
_META_TEMPLATE = f"""\
2626
Wheel-Version: {_WHEEL_VERSION}
@@ -43,13 +43,15 @@ def __init__(
4343
self,
4444
path: _Path,
4545
root_is_purelib: bool = True,
46+
compression: int = _DEFAULT_COMPRESSION,
4647
generator: Optional[str] = None,
4748
timestamp: Optional[int] = None,
4849
):
4950
self._path = Path(path)
5051
self._root_is_purelib = root_is_purelib
5152
self._generator = generator
52-
self._zip = ZipFile(self._path, "w", compression=_COMPRESSION)
53+
self._compression = compression
54+
self._zip = ZipFile(self._path, "w", compression=compression)
5355
self._records: Dict[str, Tuple[str, int]] = {}
5456

5557
basename = str(self._path.with_suffix("").name)
@@ -83,7 +85,7 @@ def add_existing_file(self, arcname: str, file: _Path):
8385
zipinfo = ZipInfo(arcname, self._timestamp)
8486
attr = stat.S_IMODE(file_stat.st_mode) | stat.S_IFMT(file_stat.st_mode)
8587
zipinfo.external_attr = attr << 16
86-
zipinfo.compress_type = _COMPRESSION
88+
zipinfo.compress_type = self._compression
8789

8890
with open(file, "rb") as src, self._zip.open(zipinfo, "w") as dst:
8991
while True:
@@ -126,7 +128,7 @@ def new_file(self, arcname: str, contents: _StrOrIter, permissions: int = 0o664)
126128
"""
127129
zipinfo = ZipInfo(arcname, self._timestamp)
128130
zipinfo.external_attr = (permissions | stat.S_IFREG) << 16
129-
zipinfo.compress_type = _COMPRESSION
131+
zipinfo.compress_type = self._compression
130132
hashsum = hashlib.new(_HASH_ALG)
131133
file_size = 0
132134
iter_contents = [contents] if isinstance(contents, str) else contents
@@ -142,7 +144,7 @@ def _save_record(self):
142144
arcname = f"{self._dist_info}/RECORD"
143145
zipinfo = ZipInfo(arcname, self._timestamp)
144146
zipinfo.external_attr = (0o664 | stat.S_IFREG) << 16
145-
zipinfo.compress_type = _COMPRESSION
147+
zipinfo.compress_type = self._compression
146148
out = self._zip.open(zipinfo, "w")
147149
buf = io.TextIOWrapper(out, encoding="utf-8")
148150
with out, buf:

0 commit comments

Comments
 (0)