Skip to content

Commit 2fa96fc

Browse files
compress the link parsing
1 parent 49385c8 commit 2fa96fc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/pip/_internal/index/package_finder.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import enum
44
import functools
5+
import gzip
56
import itertools
67
import json
78
import logging
@@ -935,7 +936,7 @@ def _write_http_cache_info(
935936
def _try_load_parsed_links_cache(parsed_links_path: Path) -> Optional[List[Link]]:
936937
page_links: Optional[List[Link]] = None
937938
try:
938-
with parsed_links_path.open("r") as f:
939+
with gzip.open(parsed_links_path, mode="rt", encoding="utf-8") as f:
939940
logger.debug("reading page links from cache %s", parsed_links_path)
940941
cached_links = json.load(f)
941942
page_links = []
@@ -967,7 +968,7 @@ def _write_parsed_links_cache(
967968
page_links.append(link)
968969

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

973974
return page_links
@@ -977,7 +978,7 @@ def _try_load_installation_candidate_cache(
977978
cached_candidates_path: Path,
978979
) -> Optional[List[InstallationCandidate]]:
979980
try:
980-
with cached_candidates_path.open("r") as f:
981+
with gzip.open(cached_candidates_path, mode="rt", encoding="utf-8") as f:
981982
serialized_candidates = json.load(f)
982983
logger.debug("read serialized candidates from %s", cached_candidates_path)
983984
package_links: List[InstallationCandidate] = []
@@ -1011,7 +1012,7 @@ def _write_installation_candidate_cache(
10111012
)
10121013
for candidate in candidates
10131014
]
1014-
with cached_candidates_path.open("w") as f:
1015+
with gzip.open(cached_candidates_path, mode="wt", encoding="utf-8") as f:
10151016
logger.debug("writing serialized candidates to %s", f.name)
10161017
json.dump(serialized_candidates, f)
10171018
return candidates

0 commit comments

Comments
 (0)