__init__.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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("appdirs")
  52. vendored("cachecontrol")
  53. vendored("certifi")
  54. vendored("colorama")
  55. vendored("contextlib2")
  56. vendored("distlib")
  57. vendored("distro")
  58. vendored("html5lib")
  59. vendored("six")
  60. vendored("six.moves")
  61. vendored("six.moves.urllib")
  62. vendored("six.moves.urllib.parse")
  63. vendored("packaging")
  64. vendored("packaging.version")
  65. vendored("packaging.specifiers")
  66. vendored("pep517")
  67. vendored("pkg_resources")
  68. vendored("progress")
  69. vendored("retrying")
  70. vendored("requests")
  71. vendored("requests.exceptions")
  72. vendored("requests.packages")
  73. vendored("requests.packages.urllib3")
  74. vendored("requests.packages.urllib3._collections")
  75. vendored("requests.packages.urllib3.connection")
  76. vendored("requests.packages.urllib3.connectionpool")
  77. vendored("requests.packages.urllib3.contrib")
  78. vendored("requests.packages.urllib3.contrib.ntlmpool")
  79. vendored("requests.packages.urllib3.contrib.pyopenssl")
  80. vendored("requests.packages.urllib3.exceptions")
  81. vendored("requests.packages.urllib3.fields")
  82. vendored("requests.packages.urllib3.filepost")
  83. vendored("requests.packages.urllib3.packages")
  84. vendored("requests.packages.urllib3.packages.ordered_dict")
  85. vendored("requests.packages.urllib3.packages.six")
  86. vendored("requests.packages.urllib3.packages.ssl_match_hostname")
  87. vendored("requests.packages.urllib3.packages.ssl_match_hostname."
  88. "_implementation")
  89. vendored("requests.packages.urllib3.poolmanager")
  90. vendored("requests.packages.urllib3.request")
  91. vendored("requests.packages.urllib3.response")
  92. vendored("requests.packages.urllib3.util")
  93. vendored("requests.packages.urllib3.util.connection")
  94. vendored("requests.packages.urllib3.util.request")
  95. vendored("requests.packages.urllib3.util.response")
  96. vendored("requests.packages.urllib3.util.retry")
  97. vendored("requests.packages.urllib3.util.ssl_")
  98. vendored("requests.packages.urllib3.util.timeout")
  99. vendored("requests.packages.urllib3.util.url")
  100. vendored("resolvelib")
  101. vendored("toml")
  102. vendored("toml.encoder")
  103. vendored("toml.decoder")
  104. vendored("urllib3")