Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/models/search_scope.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
| author | guerler |
|---|---|
| date | Mon, 27 Jul 2020 03:47:31 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9e54283cc701 |
|---|---|
| 1 import itertools | |
| 2 import logging | |
| 3 import os | |
| 4 import posixpath | |
| 5 | |
| 6 from pip._vendor.packaging.utils import canonicalize_name | |
| 7 from pip._vendor.six.moves.urllib import parse as urllib_parse | |
| 8 | |
| 9 from pip._internal.models.index import PyPI | |
| 10 from pip._internal.utils.compat import has_tls | |
| 11 from pip._internal.utils.misc import normalize_path, redact_auth_from_url | |
| 12 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
| 13 | |
| 14 if MYPY_CHECK_RUNNING: | |
| 15 from typing import List | |
| 16 | |
| 17 | |
| 18 logger = logging.getLogger(__name__) | |
| 19 | |
| 20 | |
| 21 class SearchScope(object): | |
| 22 | |
| 23 """ | |
| 24 Encapsulates the locations that pip is configured to search. | |
| 25 """ | |
| 26 | |
| 27 @classmethod | |
| 28 def create( | |
| 29 cls, | |
| 30 find_links, # type: List[str] | |
| 31 index_urls, # type: List[str] | |
| 32 ): | |
| 33 # type: (...) -> SearchScope | |
| 34 """ | |
| 35 Create a SearchScope object after normalizing the `find_links`. | |
| 36 """ | |
| 37 # Build find_links. If an argument starts with ~, it may be | |
| 38 # a local file relative to a home directory. So try normalizing | |
| 39 # it and if it exists, use the normalized version. | |
| 40 # This is deliberately conservative - it might be fine just to | |
| 41 # blindly normalize anything starting with a ~... | |
| 42 built_find_links = [] # type: List[str] | |
| 43 for link in find_links: | |
| 44 if link.startswith('~'): | |
| 45 new_link = normalize_path(link) | |
| 46 if os.path.exists(new_link): | |
| 47 link = new_link | |
| 48 built_find_links.append(link) | |
| 49 | |
| 50 # If we don't have TLS enabled, then WARN if anyplace we're looking | |
| 51 # relies on TLS. | |
| 52 if not has_tls(): | |
| 53 for link in itertools.chain(index_urls, built_find_links): | |
| 54 parsed = urllib_parse.urlparse(link) | |
| 55 if parsed.scheme == 'https': | |
| 56 logger.warning( | |
| 57 'pip is configured with locations that require ' | |
| 58 'TLS/SSL, however the ssl module in Python is not ' | |
| 59 'available.' | |
| 60 ) | |
| 61 break | |
| 62 | |
| 63 return cls( | |
| 64 find_links=built_find_links, | |
| 65 index_urls=index_urls, | |
| 66 ) | |
| 67 | |
| 68 def __init__( | |
| 69 self, | |
| 70 find_links, # type: List[str] | |
| 71 index_urls, # type: List[str] | |
| 72 ): | |
| 73 # type: (...) -> None | |
| 74 self.find_links = find_links | |
| 75 self.index_urls = index_urls | |
| 76 | |
| 77 def get_formatted_locations(self): | |
| 78 # type: () -> str | |
| 79 lines = [] | |
| 80 if self.index_urls and self.index_urls != [PyPI.simple_url]: | |
| 81 lines.append( | |
| 82 'Looking in indexes: {}'.format(', '.join( | |
| 83 redact_auth_from_url(url) for url in self.index_urls)) | |
| 84 ) | |
| 85 if self.find_links: | |
| 86 lines.append( | |
| 87 'Looking in links: {}'.format(', '.join( | |
| 88 redact_auth_from_url(url) for url in self.find_links)) | |
| 89 ) | |
| 90 return '\n'.join(lines) | |
| 91 | |
| 92 def get_index_urls_locations(self, project_name): | |
| 93 # type: (str) -> List[str] | |
| 94 """Returns the locations found via self.index_urls | |
| 95 | |
| 96 Checks the url_name on the main (first in the list) index and | |
| 97 use this url_name to produce all locations | |
| 98 """ | |
| 99 | |
| 100 def mkurl_pypi_url(url): | |
| 101 # type: (str) -> str | |
| 102 loc = posixpath.join( | |
| 103 url, | |
| 104 urllib_parse.quote(canonicalize_name(project_name))) | |
| 105 # For maximum compatibility with easy_install, ensure the path | |
| 106 # ends in a trailing slash. Although this isn't in the spec | |
| 107 # (and PyPI can handle it without the slash) some other index | |
| 108 # implementations might break if they relied on easy_install's | |
| 109 # behavior. | |
| 110 if not loc.endswith('/'): | |
| 111 loc = loc + '/' | |
| 112 return loc | |
| 113 | |
| 114 return [mkurl_pypi_url(url) for url in self.index_urls] |
