__init__.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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("dependency-groups")
  54. vendored("distlib")
  55. vendored("distro")
  56. vendored("packaging")
  57. vendored("packaging.version")
  58. vendored("packaging.specifiers")
  59. vendored("pkg_resources")
  60. vendored("platformdirs")
  61. vendored("progress")
  62. vendored("pyproject_hooks")
  63. vendored("requests")
  64. vendored("requests.exceptions")
  65. vendored("requests.packages")
  66. vendored("requests.packages.urllib3")
  67. vendored("requests.packages.urllib3._collections")
  68. vendored("requests.packages.urllib3.connection")
  69. vendored("requests.packages.urllib3.connectionpool")
  70. vendored("requests.packages.urllib3.contrib")
  71. vendored("requests.packages.urllib3.contrib.ntlmpool")
  72. vendored("requests.packages.urllib3.contrib.pyopenssl")
  73. vendored("requests.packages.urllib3.exceptions")
  74. vendored("requests.packages.urllib3.fields")
  75. vendored("requests.packages.urllib3.filepost")
  76. vendored("requests.packages.urllib3.packages")
  77. vendored("requests.packages.urllib3.packages.ordered_dict")
  78. vendored("requests.packages.urllib3.packages.six")
  79. vendored("requests.packages.urllib3.packages.ssl_match_hostname")
  80. vendored("requests.packages.urllib3.packages.ssl_match_hostname."
  81. "_implementation")
  82. vendored("requests.packages.urllib3.poolmanager")
  83. vendored("requests.packages.urllib3.request")
  84. vendored("requests.packages.urllib3.response")
  85. vendored("requests.packages.urllib3.util")
  86. vendored("requests.packages.urllib3.util.connection")
  87. vendored("requests.packages.urllib3.util.request")
  88. vendored("requests.packages.urllib3.util.response")
  89. vendored("requests.packages.urllib3.util.retry")
  90. vendored("requests.packages.urllib3.util.ssl_")
  91. vendored("requests.packages.urllib3.util.timeout")
  92. vendored("requests.packages.urllib3.util.url")
  93. vendored("resolvelib")
  94. vendored("rich")
  95. vendored("rich.console")
  96. vendored("rich.highlighter")
  97. vendored("rich.logging")
  98. vendored("rich.markup")
  99. vendored("rich.progress")
  100. vendored("rich.segment")
  101. vendored("rich.style")
  102. vendored("rich.text")
  103. vendored("rich.traceback")
  104. if sys.version_info < (3, 11):
  105. vendored("tomli")
  106. vendored("truststore")
  107. vendored("urllib3")