comparison lib/python3.8/site-packages/pip/_internal/commands/debug.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 # The following comment should be removed at some point in the future.
2 # mypy: disallow-untyped-defs=False
3
4 from __future__ import absolute_import
5
6 import locale
7 import logging
8 import os
9 import sys
10
11 from pip._vendor.certifi import where
12
13 from pip._internal.cli import cmdoptions
14 from pip._internal.cli.base_command import Command
15 from pip._internal.cli.cmdoptions import make_target_python
16 from pip._internal.cli.status_codes import SUCCESS
17 from pip._internal.utils.logging import indent_log
18 from pip._internal.utils.misc import get_pip_version
19 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
20
21 if MYPY_CHECK_RUNNING:
22 from typing import Any, List, Optional
23 from optparse import Values
24
25 logger = logging.getLogger(__name__)
26
27
28 def show_value(name, value):
29 # type: (str, Optional[str]) -> None
30 logger.info('{}: {}'.format(name, value))
31
32
33 def show_sys_implementation():
34 # type: () -> None
35 logger.info('sys.implementation:')
36 if hasattr(sys, 'implementation'):
37 implementation = sys.implementation # type: ignore
38 implementation_name = implementation.name
39 else:
40 implementation_name = ''
41
42 with indent_log():
43 show_value('name', implementation_name)
44
45
46 def show_tags(options):
47 # type: (Values) -> None
48 tag_limit = 10
49
50 target_python = make_target_python(options)
51 tags = target_python.get_tags()
52
53 # Display the target options that were explicitly provided.
54 formatted_target = target_python.format_given()
55 suffix = ''
56 if formatted_target:
57 suffix = ' (target: {})'.format(formatted_target)
58
59 msg = 'Compatible tags: {}{}'.format(len(tags), suffix)
60 logger.info(msg)
61
62 if options.verbose < 1 and len(tags) > tag_limit:
63 tags_limited = True
64 tags = tags[:tag_limit]
65 else:
66 tags_limited = False
67
68 with indent_log():
69 for tag in tags:
70 logger.info(str(tag))
71
72 if tags_limited:
73 msg = (
74 '...\n'
75 '[First {tag_limit} tags shown. Pass --verbose to show all.]'
76 ).format(tag_limit=tag_limit)
77 logger.info(msg)
78
79
80 def ca_bundle_info(config):
81 levels = set()
82 for key, value in config.items():
83 levels.add(key.split('.')[0])
84
85 if not levels:
86 return "Not specified"
87
88 levels_that_override_global = ['install', 'wheel', 'download']
89 global_overriding_level = [
90 level for level in levels if level in levels_that_override_global
91 ]
92 if not global_overriding_level:
93 return 'global'
94
95 levels.remove('global')
96 return ", ".join(levels)
97
98
99 class DebugCommand(Command):
100 """
101 Display debug information.
102 """
103
104 usage = """
105 %prog <options>"""
106 ignore_require_venv = True
107
108 def __init__(self, *args, **kw):
109 super(DebugCommand, self).__init__(*args, **kw)
110
111 cmd_opts = self.cmd_opts
112 cmdoptions.add_target_python_options(cmd_opts)
113 self.parser.insert_option_group(0, cmd_opts)
114 self.parser.config.load()
115
116 def run(self, options, args):
117 # type: (Values, List[Any]) -> int
118 logger.warning(
119 "This command is only meant for debugging. "
120 "Do not use this with automation for parsing and getting these "
121 "details, since the output and options of this command may "
122 "change without notice."
123 )
124 show_value('pip version', get_pip_version())
125 show_value('sys.version', sys.version)
126 show_value('sys.executable', sys.executable)
127 show_value('sys.getdefaultencoding', sys.getdefaultencoding())
128 show_value('sys.getfilesystemencoding', sys.getfilesystemencoding())
129 show_value(
130 'locale.getpreferredencoding', locale.getpreferredencoding(),
131 )
132 show_value('sys.platform', sys.platform)
133 show_sys_implementation()
134
135 show_value("'cert' config value", ca_bundle_info(self.parser.config))
136 show_value("REQUESTS_CA_BUNDLE", os.environ.get('REQUESTS_CA_BUNDLE'))
137 show_value("CURL_CA_BUNDLE", os.environ.get('CURL_CA_BUNDLE'))
138 show_value("pip._vendor.certifi.where()", where())
139
140 show_tags(options)
141
142 return SUCCESS