diff options
author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2023-03-30 20:23:26 +0100 |
---|---|---|
committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2023-05-03 14:10:22 +0100 |
commit | c8dc1ed77d2313c720a1e03f518edf73e3db87d0 (patch) | |
tree | 4ca2384da3654291f80d3ded545f40231044cb2d | |
parent | 376427184e4c06341f6a43ad1c478262d6d2e297 (diff) | |
download | python-setuptools-git-c8dc1ed77d2313c720a1e03f518edf73e3db87d0.tar.gz |
Enable different compressions in WheelBuilder
-rw-r--r-- | setuptools/_wheelbuilder.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/setuptools/_wheelbuilder.py b/setuptools/_wheelbuilder.py index 742dd61a..2e0f7d1c 100644 --- a/setuptools/_wheelbuilder.py +++ b/setuptools/_wheelbuilder.py @@ -20,7 +20,7 @@ _StrOrIter = Union[str, Iterable[str]] _HASH_ALG = "sha256" _HASH_BUF_SIZE = 65536 _MINIMUM_TIMESTAMP = 315532800 # 1980-01-01 00:00:00 UTC -_COMPRESSION = ZIP_DEFLATED +_DEFAULT_COMPRESSION = ZIP_DEFLATED _WHEEL_VERSION = "1.0" _META_TEMPLATE = f"""\ Wheel-Version: {_WHEEL_VERSION} @@ -43,13 +43,15 @@ class WheelBuilder: self, path: _Path, root_is_purelib: bool = True, + compression: int = _DEFAULT_COMPRESSION, generator: Optional[str] = None, timestamp: Optional[int] = None, ): self._path = Path(path) self._root_is_purelib = root_is_purelib self._generator = generator - self._zip = ZipFile(self._path, "w", compression=_COMPRESSION) + self._compression = compression + self._zip = ZipFile(self._path, "w", compression=compression) self._records: Dict[str, Tuple[str, int]] = {} basename = str(self._path.with_suffix("").name) @@ -83,7 +85,7 @@ class WheelBuilder: zipinfo = ZipInfo(arcname, self._timestamp) attr = stat.S_IMODE(file_stat.st_mode) | stat.S_IFMT(file_stat.st_mode) zipinfo.external_attr = attr << 16 - zipinfo.compress_type = _COMPRESSION + zipinfo.compress_type = self._compression with open(file, "rb") as src, self._zip.open(zipinfo, "w") as dst: while True: @@ -126,7 +128,7 @@ class WheelBuilder: """ zipinfo = ZipInfo(arcname, self._timestamp) zipinfo.external_attr = (permissions | stat.S_IFREG) << 16 - zipinfo.compress_type = _COMPRESSION + zipinfo.compress_type = self._compression hashsum = hashlib.new(_HASH_ALG) file_size = 0 iter_contents = [contents] if isinstance(contents, str) else contents @@ -142,7 +144,7 @@ class WheelBuilder: arcname = f"{self._dist_info}/RECORD" zipinfo = ZipInfo(arcname, self._timestamp) zipinfo.external_attr = (0o664 | stat.S_IFREG) << 16 - zipinfo.compress_type = _COMPRESSION + zipinfo.compress_type = self._compression out = self._zip.open(zipinfo, "w") buf = io.TextIOWrapper(out, encoding="utf-8") with out, buf: |