Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pip/_vendor/__init__.py: 11%

76 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:48 +0000

1""" 

2pip._vendor is for vendoring dependencies of pip to prevent needing pip to 

3depend on something external. 

4 

5Files inside of pip._vendor should be considered immutable and should only be 

6updated to versions from upstream. 

7""" 

8from __future__ import absolute_import 

9 

10import glob 

11import os.path 

12import sys 

13 

14# Downstream redistributors which have debundled our dependencies should also 

15# patch this value to be true. This will trigger the additional patching 

16# to cause things like "six" to be available as pip. 

17DEBUNDLED = False 

18 

19# By default, look in this directory for a bunch of .whl files which we will 

20# add to the beginning of sys.path before attempting to import anything. This 

21# is done to support downstream re-distributors like Debian and Fedora who 

22# wish to create their own Wheels for our dependencies to aid in debundling. 

23WHEEL_DIR = os.path.abspath(os.path.dirname(__file__)) 

24 

25 

26# Define a small helper function to alias our vendored modules to the real ones 

27# if the vendored ones do not exist. This idea of this was taken from 

28# https://github.com/kennethreitz/requests/pull/2567. 

29def vendored(modulename): 

30 vendored_name = "{0}.{1}".format(__name__, modulename) 

31 

32 try: 

33 __import__(modulename, globals(), locals(), level=0) 

34 except ImportError: 

35 # We can just silently allow import failures to pass here. If we 

36 # got to this point it means that ``import pip._vendor.whatever`` 

37 # failed and so did ``import whatever``. Since we're importing this 

38 # upfront in an attempt to alias imports, not erroring here will 

39 # just mean we get a regular import error whenever pip *actually* 

40 # tries to import one of these modules to use it, which actually 

41 # gives us a better error message than we would have otherwise 

42 # gotten. 

43 pass 

44 else: 

45 sys.modules[vendored_name] = sys.modules[modulename] 

46 base, head = vendored_name.rsplit(".", 1) 

47 setattr(sys.modules[base], head, sys.modules[modulename]) 

48 

49 

50# If we're operating in a debundled setup, then we want to go ahead and trigger 

51# the aliasing of our vendored libraries as well as looking for wheels to add 

52# to our sys.path. This will cause all of this code to be a no-op typically 

53# however downstream redistributors can enable it in a consistent way across 

54# all platforms. 

55if DEBUNDLED: 

56 # Actually look inside of WHEEL_DIR to find .whl files and add them to the 

57 # front of our sys.path. 

58 sys.path[:] = glob.glob(os.path.join(WHEEL_DIR, "*.whl")) + sys.path 

59 

60 # Actually alias all of our vendored dependencies. 

61 vendored("cachecontrol") 

62 vendored("certifi") 

63 vendored("colorama") 

64 vendored("distlib") 

65 vendored("distro") 

66 vendored("six") 

67 vendored("six.moves") 

68 vendored("six.moves.urllib") 

69 vendored("six.moves.urllib.parse") 

70 vendored("packaging") 

71 vendored("packaging.version") 

72 vendored("packaging.specifiers") 

73 vendored("pep517") 

74 vendored("pkg_resources") 

75 vendored("platformdirs") 

76 vendored("progress") 

77 vendored("requests") 

78 vendored("requests.exceptions") 

79 vendored("requests.packages") 

80 vendored("requests.packages.urllib3") 

81 vendored("requests.packages.urllib3._collections") 

82 vendored("requests.packages.urllib3.connection") 

83 vendored("requests.packages.urllib3.connectionpool") 

84 vendored("requests.packages.urllib3.contrib") 

85 vendored("requests.packages.urllib3.contrib.ntlmpool") 

86 vendored("requests.packages.urllib3.contrib.pyopenssl") 

87 vendored("requests.packages.urllib3.exceptions") 

88 vendored("requests.packages.urllib3.fields") 

89 vendored("requests.packages.urllib3.filepost") 

90 vendored("requests.packages.urllib3.packages") 

91 vendored("requests.packages.urllib3.packages.ordered_dict") 

92 vendored("requests.packages.urllib3.packages.six") 

93 vendored("requests.packages.urllib3.packages.ssl_match_hostname") 

94 vendored("requests.packages.urllib3.packages.ssl_match_hostname." 

95 "_implementation") 

96 vendored("requests.packages.urllib3.poolmanager") 

97 vendored("requests.packages.urllib3.request") 

98 vendored("requests.packages.urllib3.response") 

99 vendored("requests.packages.urllib3.util") 

100 vendored("requests.packages.urllib3.util.connection") 

101 vendored("requests.packages.urllib3.util.request") 

102 vendored("requests.packages.urllib3.util.response") 

103 vendored("requests.packages.urllib3.util.retry") 

104 vendored("requests.packages.urllib3.util.ssl_") 

105 vendored("requests.packages.urllib3.util.timeout") 

106 vendored("requests.packages.urllib3.util.url") 

107 vendored("resolvelib") 

108 vendored("rich") 

109 vendored("rich.console") 

110 vendored("rich.highlighter") 

111 vendored("rich.logging") 

112 vendored("rich.markup") 

113 vendored("rich.progress") 

114 vendored("rich.segment") 

115 vendored("rich.style") 

116 vendored("rich.text") 

117 vendored("rich.traceback") 

118 vendored("tenacity") 

119 vendored("tomli") 

120 vendored("urllib3")