Get the cache working for obtaining file hashes

This commit is contained in:
Matt Davis
2023-08-25 10:44:21 -04:00
committed by Oz Tiram
parent 4a59b92836
commit d7aed28967
3 changed files with 12 additions and 11 deletions
+3 -1
View File
@@ -240,7 +240,9 @@ class Project:
session = self.sessions[source["name"]]
else:
session = get_requests_session(
self.s.PIPENV_MAX_RETRIES, source.get("verify_ssl", True)
self.s.PIPENV_MAX_RETRIES,
source.get("verify_ssl", True),
cache_dir=self.s.PIPENV_CACHE_DIR,
)
self.sessions[source["name"]] = session
return session
+5 -4
View File
@@ -12,7 +12,8 @@ from urllib import parse as urllib_parse
from urllib import request as urllib_request
from urllib.parse import quote, urlparse
from pipenv.patched.pip._vendor.requests import Session
from pipenv.patched.pip._internal.locations import USER_CACHE_DIR
from pipenv.patched.pip._internal.network.download import PipSession
from pipenv.utils import err
@@ -114,12 +115,12 @@ def path_to_url(path):
@contextmanager
def open_file(link, session: Optional[Session] = None, stream: bool = True):
def open_file(link, session: Optional[PipSession] = None, stream: bool = False):
"""Open local or remote file for reading.
:param pipenv.patched.pip._internal.index.Link link: A link object from resolving dependencies with
pip, or else a URL.
:param Optional[Session] session: A :class:`~requests.Session` instance
:param Optional[PipSession] session: A :class:`~PipSession` instance
:param bool stream: Whether to stream the content if remote, default True
:raises ValueError: If link points to a local directory.
:return: a context manager to the opened file-like object
@@ -145,7 +146,7 @@ def open_file(link, session: Optional[Session] = None, stream: bool = True):
# Remote URL
headers = {"Accept-Encoding": "identity"}
if not session:
session = Session()
session = PipSession(cache=USER_CACHE_DIR)
resp = session.get(link, headers=headers, stream=stream)
if resp.status_code != 200:
err.print(f"HTTP error {resp.status_code} while getting {link}")
+4 -6
View File
@@ -3,19 +3,17 @@ import re
from html.parser import HTMLParser
from urllib.parse import urlparse
from pipenv.patched.pip._vendor import requests
from pipenv.patched.pip._vendor.requests.adapters import HTTPAdapter
from pipenv.patched.pip._internal.locations import USER_CACHE_DIR
from pipenv.patched.pip._internal.network.download import PipSession
from pipenv.patched.pip._vendor.urllib3 import util as urllib3_util
def get_requests_session(max_retries=1, verify_ssl=True):
def get_requests_session(max_retries=1, verify_ssl=True, cache_dir=USER_CACHE_DIR):
"""Load requests lazily."""
pip_client_cert = os.environ.get("PIP_CLIENT_CERT")
requests_session = requests.Session()
requests_session = PipSession(cache=cache_dir, retries=max_retries)
if pip_client_cert:
requests_session.cert = pip_client_cert
adapter = HTTPAdapter(max_retries=max_retries)
requests_session.mount("https://", adapter)
if verify_ssl is False:
requests_session.verify = False
return requests_session