Skip to content

Commit

Permalink
gzip compress link metadata for a slight reduction in disk space
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Sep 3, 2023
1 parent 7591507 commit 5a42ae4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# mypy: strict-optional=False

import email.errors
import gzip
import json
import mimetypes
import os
Expand Down Expand Up @@ -437,7 +438,7 @@ def _fetch_cached_metadata(
try:
cached_path = self._metadata_cache.cache_path(req.link)
os.makedirs(str(cached_path.parent), exist_ok=True)
with cached_path.open("rb") as f:
with gzip.open(cached_path, mode="rt", encoding="utf-8") as f:
logger.debug(
"found cached metadata for link %s at %s", req.link, f.name
)
Expand Down Expand Up @@ -466,7 +467,7 @@ def _cache_metadata(
try:
cached_path = self._metadata_cache.cache_path(req.link)
os.makedirs(str(cached_path.parent), exist_ok=True)
with cached_path.open("w") as f:
with gzip.open(cached_path, mode="wt", encoding="utf-8") as f:
cacheable_dist = CacheableDist.from_dist(req.link, metadata_dist)
args = cacheable_dist.to_json()
logger.debug("caching metadata for link %s at %s", req.link, f.name)
Expand Down

0 comments on commit 5a42ae4

Please sign in to comment.