From f6e5be201541a1a4be7c865a51fb688deb1a4fff Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Sat, 19 Mar 2022 06:43:53 -0400 Subject: [PATCH] refactor type hints and add a patch for this change against the pip 21 version off main. --- .../notpip/_internal/index/collector.py | 5 +- .../notpip/_internal/models/search_scope.py | 6 +- .../patches/patched/pip_index_safety.patch | 102 ++++++++++++++++++ 3 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 tasks/vendoring/patches/patched/pip_index_safety.patch diff --git a/pipenv/patched/notpip/_internal/index/collector.py b/pipenv/patched/notpip/_internal/index/collector.py index 7167ddc1..fc532c40 100644 --- a/pipenv/patched/notpip/_internal/index/collector.py +++ b/pipenv/patched/notpip/_internal/index/collector.py @@ -17,6 +17,7 @@ from optparse import Values from typing import ( Callable, Iterable, + Dict, List, MutableMapping, NamedTuple, @@ -445,7 +446,7 @@ class LinkCollector: self, session: PipSession, search_scope: SearchScope, - index_lookup: dict = None, + index_lookup: Optional[Dict[str, List[str]]] = None, ) -> None: self.search_scope = search_scope self.session = session @@ -456,7 +457,7 @@ class LinkCollector: cls, session: PipSession, options: Values, suppress_no_index: bool = False, - index_lookup: dict = None, + index_lookup: Optional[Dict[str, List[str]]] = None, ) -> "LinkCollector": """ :param session: The Session to use to make requests. diff --git a/pipenv/patched/notpip/_internal/models/search_scope.py b/pipenv/patched/notpip/_internal/models/search_scope.py index d21a5005..58154c31 100644 --- a/pipenv/patched/notpip/_internal/models/search_scope.py +++ b/pipenv/patched/notpip/_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 pipenv.patched.notpip._vendor.packaging.utils import canonicalize_name @@ -27,7 +27,7 @@ class SearchScope: cls, find_links: List[str], index_urls: List[str], - index_lookup: dict = None, + index_lookup: Optional[Dict[str, List[str]]] = None, ) -> "SearchScope": """ Create a SearchScope object after normalizing the `find_links`. @@ -68,7 +68,7 @@ class SearchScope: self, find_links: List[str], index_urls: List[str], - index_lookup: dict = None, + index_lookup: Optional[Dict[str, List[str]]] = None, ) -> None: self.find_links = find_links self.index_urls = index_urls diff --git a/tasks/vendoring/patches/patched/pip_index_safety.patch b/tasks/vendoring/patches/patched/pip_index_safety.patch new file mode 100644 index 00000000..3eea4dc1 --- /dev/null +++ b/tasks/vendoring/patches/patched/pip_index_safety.patch @@ -0,0 +1,102 @@ +diff --git a/pipenv/patched/pip/_internal/index/collector.py b/pipenv/patched/pip/_internal/index/collector.py +index 98ac9d2e..fc532c40 100644 +--- a/pipenv/patched/pip/_internal/index/collector.py ++++ b/pipenv/patched/pip/_internal/index/collector.py +@@ -17,6 +17,7 @@ from optparse import Values + from typing import ( + Callable, + Iterable, ++ Dict, + List, + MutableMapping, + NamedTuple, +@@ -445,15 +446,18 @@ 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( + cls, session: PipSession, + options: Values, +- suppress_no_index: bool = False ++ suppress_no_index: bool = False, ++ index_lookup: Optional[Dict[str, List[str]]] = None, + ) -> "LinkCollector": + """ + :param session: The Session to use to make requests. +@@ -472,10 +476,10 @@ class LinkCollector: + find_links = options.find_links or [] + + search_scope = SearchScope.create( +- find_links=find_links, index_urls=index_urls, ++ find_links=find_links, index_urls=index_urls, index_lookup=index_lookup + ) + link_collector = LinkCollector( +- session=session, search_scope=search_scope, ++ 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 4b700407..58154c31 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 pipenv.patched.notpip._vendor.packaging.utils import canonicalize_name + +@@ -20,13 +20,14 @@ class SearchScope: + Encapsulates the locations that pip is configured to search. + """ + +- __slots__ = ["find_links", "index_urls"] ++ __slots__ = ["find_links", "index_urls", "index_lookup"] + + @classmethod + def create( + cls, + find_links: List[str], + index_urls: List[str], ++ index_lookup: Optional[Dict[str, List[str]]] = None, + ) -> "SearchScope": + """ + Create a SearchScope object after normalizing the `find_links`. +@@ -60,15 +61,18 @@ class SearchScope: + return cls( + find_links=built_find_links, + index_urls=index_urls, ++ index_lookup=index_lookup + ) + + def __init__( + self, + find_links: List[str], + index_urls: List[str], ++ index_lookup: Optional[Dict[str, List[str]]] = None, + ) -> None: + self.find_links = find_links + self.index_urls = index_urls ++ self.index_lookup = index_lookup if index_lookup else {} + + def get_formatted_locations(self) -> str: + lines = [] +@@ -123,4 +127,7 @@ 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]] ++ return [mkurl_pypi_url(url) for url in index_urls]