Skip to content

Commit

Permalink
Get the cache working for obtaining file hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius authored and oz123 committed Aug 25, 2023
1 parent 4a59b92 commit d7aed28
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 3 additions & 1 deletion pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ def get_requests_session_for_source(self, source):
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
Expand Down
9 changes: 5 additions & 4 deletions pipenv/utils/fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
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


Expand Down Expand Up @@ -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
Expand All @@ -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}")
Expand Down
10 changes: 4 additions & 6 deletions pipenv/utils/internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
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
Expand Down

0 comments on commit d7aed28

Please sign in to comment.