18
18
19
19
from pip ._internal .models .link import Link
20
20
from pip ._internal .utils .filetypes import ARCHIVE_EXTENSIONS
21
- from pip ._internal .utils .misc import redact_auth_from_url
21
+ from pip ._internal .utils .misc import pairwise , redact_auth_from_url
22
22
from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
23
23
from pip ._internal .utils .urls import path_to_url , url_to_path
24
24
from pip ._internal .vcs import is_url , vcs
@@ -341,6 +341,9 @@ def wrapper(cacheable_page):
341
341
342
342
def wrapper_wrapper (page ):
343
343
# type: (HTMLPage) -> List[Link]
344
+ if page .is_index_url :
345
+ # Avoid caching when requesting pypi indices.
346
+ return list (fn (page ))
344
347
return wrapper (CacheablePageContent (page ))
345
348
346
349
return wrapper_wrapper
@@ -376,9 +379,10 @@ class HTMLPage(object):
376
379
377
380
def __init__ (
378
381
self ,
379
- content , # type: bytes
380
- encoding , # type: Optional[str]
381
- url , # type: str
382
+ content , # type: bytes
383
+ encoding , # type: Optional[str]
384
+ url , # type: str
385
+ is_index_url = False , # type: bool
382
386
):
383
387
# type: (...) -> None
384
388
"""
@@ -388,6 +392,7 @@ def __init__(
388
392
self .content = content
389
393
self .encoding = encoding
390
394
self .url = url
395
+ self .is_index_url = is_index_url
391
396
392
397
def __str__ (self ):
393
398
# type: () -> str
@@ -405,10 +410,13 @@ def _handle_get_page_fail(
405
410
meth ("Could not fetch URL %s: %s - skipping" , link , reason )
406
411
407
412
408
- def _make_html_page (response ):
409
- # type: (Response) -> HTMLPage
413
+ def _make_html_page (response , is_index_url = False ):
414
+ # type: (Response, bool ) -> HTMLPage
410
415
encoding = _get_encoding_from_headers (response .headers )
411
- return HTMLPage (response .content , encoding = encoding , url = response .url )
416
+ return HTMLPage (
417
+ response .content ,
418
+ encoding = encoding ,
419
+ url = response .url , is_index_url = is_index_url )
412
420
413
421
414
422
def _get_html_page (link , session = None ):
@@ -461,7 +469,7 @@ def _get_html_page(link, session=None):
461
469
except requests .Timeout :
462
470
_handle_get_page_fail (link , "timed out" )
463
471
else :
464
- return _make_html_page (resp )
472
+ return _make_html_page (resp , is_index_url = link . is_index_url )
465
473
return None
466
474
467
475
@@ -624,7 +632,7 @@ def collect_links(self, project_name):
624
632
# We want to filter out anything that does not have a secure origin.
625
633
url_locations = [
626
634
link for link in itertools .chain (
627
- (Link (url ) for url in index_url_loc ),
635
+ (Link (url , is_index_url = True ) for url in index_url_loc ),
628
636
(Link (url ) for url in fl_url_loc ),
629
637
)
630
638
if self .session .is_secure_origin (link )
0 commit comments