__init__.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. """
  2. pip._vendor is for vendoring dependencies of pip to prevent needing pip to
  3. depend on something external.
  4. Files inside of pip._vendor should be considered immutable and should only be
  5. updated to versions from upstream.
  6. """
  7. from __future__ import absolute_import
  8. import glob
  9. import os.path
  10. import sys
  11. # Downstream redistributors which have debundled our dependencies should also
  12. # patch this value to be true. This will trigger the additional patching
  13. # to cause things like "six" to be available as pip.
  14. DEBUNDLED = False
  15. # By default, look in this directory for a bunch of .whl files which we will
  16. # add to the beginning of sys.path before attempting to import anything. This
  17. # is done to support downstream re-distributors like Debian and Fedora who
  18. # wish to create their own Wheels for our dependencies to aid in debundling.
  19. WHEEL_DIR = os.path.abspath(os.path.dirname(__file__))
  20. # Define a small helper function to alias our vendored modules to the real ones
  21. # if the vendored ones do not exist. This idea of this was taken from
  22. # https://github.com/kennethreitz/requests/pull/2567.
  23. def vendored(modulename):
  24. vendored_name = "{0}.{1}".format(__name__, modulename)
  25. try:
  26. __import__(modulename, globals(), locals(), level=0)
  27. except ImportError:
  28. # We can just silently allow import failures to pass here. If we
  29. # got to this point it means that ``import pip._vendor.whatever``
  30. # failed and so did ``import whatever``. Since we're importing this
  31. # upfront in an attempt to alias imports, not erroring here will
  32. # just mean we get a regular import error whenever pip *actually*
  33. # tries to import one of these modules to use it, which actually
  34. # gives us a better error message than we would have otherwise
  35. # gotten.
  36. pass
  37. else:
  38. sys.modules[vendored_name] = sys.modules[modulename]
  39. base, head = vendored_name.rsplit(".", 1)
  40. setattr(sys.modules[base], head, sys.modules[modulename])
  41. # If we're operating in a debundled setup, then we want to go ahead and trigger
  42. # the aliasing of our vendored libraries as well as looking for wheels to add
  43. # to our sys.path. This will cause all of this code to be a no-op typically
  44. # however downstream redistributors can enable it in a consistent way across
  45. # all platforms.
  46. if DEBUNDLED:
  47. # Actually look inside of WHEEL_DIR to find .whl files and add them to the
  48. # front of our sys.path.
  49. sys.path[:] = glob.glob(os.path.join(WHEEL_DIR, "*.whl")) + sys.path
  50. # Actually alias all of our vendored dependencies.
  51. vendored("cachecontrol")
  52. vendored("certifi")
  53. vendored("colorama")
  54. vendored("distlib")
  55. vendored("distro")
  56. vendored("six")
  57. vendored("six.moves")
  58. vendored("six.moves.urllib")
  59. vendored("six.moves.urllib.parse")
  60. vendored("packaging")
  61. vendored("packaging.version")
  62. vendored("packaging.specifiers")
  63. vendored("pep517")
  64. vendored("pkg_resources")
  65. vendored("platformdirs")
  66. vendored("progress")
  67. vendored("requests")
  68. vendored("requests.exceptions")
  69. vendored("requests.packages")
  70. vendored("requests.packages.urllib3")
  71. vendored("requests.packages.urllib3._collections")
  72. vendored("requests.packages.urllib3.connection")
  73. vendored("requests.packages.urllib3.connectionpool")
  74. vendored("requests.packages.urllib3.contrib")
  75. vendored("requests.packages.urllib3.contrib.ntlmpool")
  76. vendored("requests.packages.urllib3.contrib.pyopenssl")
  77. vendored("requests.packages.urllib3.exceptions")
  78. vendored("requests.packages.urllib3.fields")
  79. vendored("requests.packages.urllib3.filepost")
  80. vendored("requests.packages.urllib3.packages")
  81. vendored("requests.packages.urllib3.packages.ordered_dict")
  82. vendored("requests.packages.urllib3.packages.six")
  83. vendored("requests.packages.urllib3.packages.ssl_match_hostname")
  84. vendored("requests.packages.urllib3.packages.ssl_match_hostname."
  85. "_implementation")
  86. vendored("requests.packages.urllib3.poolmanager")
  87. vendored("requests.packages.urllib3.request")
  88. vendored("requests.packages.urllib3.response")
  89. vendored("requests.packages.urllib3.util")
  90. vendored("requests.packages.urllib3.util.connection")
  91. vendored("requests.packages.urllib3.util.request")
  92. vendored("requests.packages.urllib3.util.response")
  93. vendored("requests.packages.urllib3.util.retry")
  94. vendored("requests.packages.urllib3.util.ssl_")
  95. vendored("requests.packages.urllib3.util.timeout")
  96. vendored("requests.packages.urllib3.util.url")
  97. vendored("resolvelib")
  98. vendored("rich")
  99. vendored("rich.console")
  100. vendored("rich.highlighter")
  101. vendored("rich.logging")
  102. vendored("rich.markup")
  103. vendored("rich.progress")
  104. vendored("rich.segment")
  105. vendored("rich.style")
  106. vendored("rich.text")
  107. vendored("rich.traceback")
  108. vendored("tenacity")
  109. vendored("tomli")
  110. vendored("urllib3")