File: pip_index_safety.patch

package info (click to toggle)
pipenv 2024.0.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,568 kB
  • sloc: python: 187,163; makefile: 191; javascript: 133; sh: 64
file content (103 lines) | stat: -rw-r--r-- 3,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
diff --git a/pipenv/patched/pip/_internal/index/collector.py b/pipenv/patched/pip/_internal/index/collector.py
index b3e293ea3..f27a88725 100644
--- a/pipenv/patched/pip/_internal/index/collector.py
+++ b/pipenv/patched/pip/_internal/index/collector.py
@@ -412,9 +412,11 @@ class LinkCollector:
         self,
         session: PipSession,
         search_scope: SearchScope,
+        index_lookup: Optional[Dict[str, List[str]]] = None,
     ) -> None:
         self.search_scope = search_scope
         self.session = session
+        self.index_lookup = index_lookup if index_lookup else {}

     @classmethod
     def create(
@@ -422,6 +424,7 @@ class LinkCollector:
         session: PipSession,
         options: Values,
         suppress_no_index: bool = False,
+        index_lookup: Optional[Dict[str, List[str]]] = None,
     ) -> "LinkCollector":
         """
         :param session: The Session to use to make requests.
@@ -443,10 +446,12 @@ class LinkCollector:
             find_links=find_links,
             index_urls=index_urls,
             no_index=options.no_index,
+            index_lookup=index_lookup,
         )
         link_collector = LinkCollector(
             session=session,
             search_scope=search_scope,
+            index_lookup=index_lookup,
         )
         return link_collector

diff --git a/pipenv/patched/pip/_internal/models/search_scope.py b/pipenv/patched/pip/_internal/models/search_scope.py
index fe61e8116..98a2cc97f 100644
--- a/pipenv/patched/pip/_internal/models/search_scope.py
+++ b/pipenv/patched/pip/_internal/models/search_scope.py
@@ -3,7 +3,7 @@ import logging
 import os
 import posixpath
 import urllib.parse
-from typing import List
+from typing import Dict, List, Optional

 from pip._vendor.packaging.utils import canonicalize_name

@@ -20,7 +20,7 @@ class SearchScope:
     Encapsulates the locations that pip is configured to search.
     """

-    __slots__ = ["find_links", "index_urls", "no_index"]
+    __slots__ = ["find_links", "index_urls", "no_index", "index_lookup", "index_restricted"]

     @classmethod
     def create(
@@ -28,6 +28,8 @@ class SearchScope:
         find_links: List[str],
         index_urls: List[str],
         no_index: bool,
+        index_lookup: Optional[Dict[str, List[str]]] = None,
+        index_restricted: bool = False,
     ) -> "SearchScope":
         """
         Create a SearchScope object after normalizing the `find_links`.
@@ -62,6 +64,8 @@ class SearchScope:
             find_links=built_find_links,
             index_urls=index_urls,
             no_index=no_index,
+            index_lookup=index_lookup,
+            index_restricted=index_restricted,
         )

     def __init__(
@@ -69,10 +73,14 @@ class SearchScope:
         find_links: List[str],
         index_urls: List[str],
         no_index: bool,
+        index_lookup: Optional[Dict[str, List[str]]] = None,
+        index_restricted: bool = False,
     ) -> None:
         self.find_links = find_links
         self.index_urls = index_urls
         self.no_index = no_index
+        self.index_lookup = index_lookup if index_lookup else {}
+        self.index_restricted = index_restricted

     def get_formatted_locations(self) -> str:
         lines = []
@@ -129,4 +137,9 @@ class SearchScope:
                 loc = loc + "/"
             return loc

-        return [mkurl_pypi_url(url) for url in self.index_urls]
+        index_urls = self.index_urls
+        if project_name in self.index_lookup:
+            index_urls = [self.index_lookup[project_name]]
+        elif self.index_restricted and self.index_urls:
+            index_urls = [self.index_urls[0]]
+        return [mkurl_pypi_url(url) for url in index_urls]