Skip to content

Commit

Permalink
compress the link parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Jan 11, 2024
1 parent 3878473 commit 58a145a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/pip/_internal/index/package_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import enum
import functools
import gzip
import itertools
import json
import logging
Expand Down Expand Up @@ -935,7 +936,7 @@ def _write_http_cache_info(
def _try_load_parsed_links_cache(parsed_links_path: Path) -> Optional[List[Link]]:
page_links: Optional[List[Link]] = None
try:
with parsed_links_path.open("r") as f:
with gzip.open(parsed_links_path, mode="rt", encoding="utf-8") as f:
logger.debug("reading page links from cache %s", parsed_links_path)
cached_links = json.load(f)
page_links = []
Expand Down Expand Up @@ -967,7 +968,7 @@ def _write_parsed_links_cache(
page_links.append(link)

logger.debug("writing page links to %s", parsed_links_path)
with parsed_links_path.open("w") as f:
with gzip.open(parsed_links_path, mode="wt", encoding="utf-8") as f:
json.dump(cacheable_links, f)

return page_links
Expand All @@ -977,7 +978,7 @@ def _try_load_installation_candidate_cache(
cached_candidates_path: Path,
) -> Optional[List[InstallationCandidate]]:
try:
with cached_candidates_path.open("r") as f:
with gzip.open(cached_candidates_path, mode="rt", encoding="utf-8") as f:
serialized_candidates = json.load(f)
logger.debug("read serialized candidates from %s", cached_candidates_path)
package_links: List[InstallationCandidate] = []
Expand Down Expand Up @@ -1011,7 +1012,7 @@ def _write_installation_candidate_cache(
}
for candidate in candidates
]
with cached_candidates_path.open("w") as f:
with gzip.open(cached_candidates_path, mode="wt", encoding="utf-8") as f:
logger.debug("writing serialized candidates to %s", f.name)
json.dump(serialized_candidates, f)
return candidates
Expand Down

0 comments on commit 58a145a

Please sign in to comment.