Skip to content

Commit 2089c05

Browse files
gzip compress link metadata for a slight reduction in disk space
1 parent 635539b commit 2089c05

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# mypy: strict-optional=False
66

77
import email.errors
8+
import gzip
89
import json
910
import mimetypes
1011
import os
@@ -437,7 +438,7 @@ def _fetch_cached_metadata(
437438
try:
438439
cached_path = self._metadata_cache.cache_path(req.link)
439440
os.makedirs(str(cached_path.parent), exist_ok=True)
440-
with cached_path.open("rb") as f:
441+
with gzip.open(cached_path, mode="rt", encoding="utf-8") as f:
441442
logger.debug(
442443
"found cached metadata for link %s at %s", req.link, f.name
443444
)
@@ -466,7 +467,7 @@ def _cache_metadata(
466467
try:
467468
cached_path = self._metadata_cache.cache_path(req.link)
468469
os.makedirs(str(cached_path.parent), exist_ok=True)
469-
with cached_path.open("w") as f:
470+
with gzip.open(cached_path, mode="wt", encoding="utf-8") as f:
470471
cacheable_dist = CacheableDist.from_dist(req.link, metadata_dist)
471472
args = cacheable_dist.to_json()
472473
logger.debug("caching metadata for link %s at %s", req.link, f.name)

0 commit comments

Comments
 (0)