You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

debug.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # The following comment should be removed at some point in the future.
  2. # mypy: disallow-untyped-defs=False
  3. from __future__ import absolute_import
  4. import locale
  5. import logging
  6. import sys
  7. from pip._internal.cli import cmdoptions
  8. from pip._internal.cli.base_command import Command
  9. from pip._internal.cli.cmdoptions import make_target_python
  10. from pip._internal.cli.status_codes import SUCCESS
  11. from pip._internal.utils.logging import indent_log
  12. from pip._internal.utils.misc import get_pip_version
  13. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  14. from pip._internal.wheel import format_tag
  15. if MYPY_CHECK_RUNNING:
  16. from typing import Any, List
  17. from optparse import Values
  18. logger = logging.getLogger(__name__)
  19. def show_value(name, value):
  20. # type: (str, str) -> None
  21. logger.info('{}: {}'.format(name, value))
  22. def show_sys_implementation():
  23. # type: () -> None
  24. logger.info('sys.implementation:')
  25. if hasattr(sys, 'implementation'):
  26. implementation = sys.implementation # type: ignore
  27. implementation_name = implementation.name
  28. else:
  29. implementation_name = ''
  30. with indent_log():
  31. show_value('name', implementation_name)
  32. def show_tags(options):
  33. # type: (Values) -> None
  34. tag_limit = 10
  35. target_python = make_target_python(options)
  36. tags = target_python.get_tags()
  37. # Display the target options that were explicitly provided.
  38. formatted_target = target_python.format_given()
  39. suffix = ''
  40. if formatted_target:
  41. suffix = ' (target: {})'.format(formatted_target)
  42. msg = 'Compatible tags: {}{}'.format(len(tags), suffix)
  43. logger.info(msg)
  44. if options.verbose < 1 and len(tags) > tag_limit:
  45. tags_limited = True
  46. tags = tags[:tag_limit]
  47. else:
  48. tags_limited = False
  49. with indent_log():
  50. for tag in tags:
  51. logger.info(format_tag(tag))
  52. if tags_limited:
  53. msg = (
  54. '...\n'
  55. '[First {tag_limit} tags shown. Pass --verbose to show all.]'
  56. ).format(tag_limit=tag_limit)
  57. logger.info(msg)
  58. class DebugCommand(Command):
  59. """
  60. Display debug information.
  61. """
  62. usage = """
  63. %prog <options>"""
  64. ignore_require_venv = True
  65. def __init__(self, *args, **kw):
  66. super(DebugCommand, self).__init__(*args, **kw)
  67. cmd_opts = self.cmd_opts
  68. cmdoptions.add_target_python_options(cmd_opts)
  69. self.parser.insert_option_group(0, cmd_opts)
  70. def run(self, options, args):
  71. # type: (Values, List[Any]) -> int
  72. logger.warning(
  73. "This command is only meant for debugging. "
  74. "Do not use this with automation for parsing and getting these "
  75. "details, since the output and options of this command may "
  76. "change without notice."
  77. )
  78. show_value('pip version', get_pip_version())
  79. show_value('sys.version', sys.version)
  80. show_value('sys.executable', sys.executable)
  81. show_value('sys.getdefaultencoding', sys.getdefaultencoding())
  82. show_value('sys.getfilesystemencoding', sys.getfilesystemencoding())
  83. show_value(
  84. 'locale.getpreferredencoding', locale.getpreferredencoding(),
  85. )
  86. show_value('sys.platform', sys.platform)
  87. show_sys_implementation()
  88. show_tags(options)
  89. return SUCCESS