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.

__init__.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """
  2. Package containing all pip commands
  3. """
  4. from __future__ import absolute_import
  5. from pip._internal.commands.completion import CompletionCommand
  6. from pip._internal.commands.configuration import ConfigurationCommand
  7. from pip._internal.commands.download import DownloadCommand
  8. from pip._internal.commands.freeze import FreezeCommand
  9. from pip._internal.commands.hash import HashCommand
  10. from pip._internal.commands.help import HelpCommand
  11. from pip._internal.commands.list import ListCommand
  12. from pip._internal.commands.check import CheckCommand
  13. from pip._internal.commands.search import SearchCommand
  14. from pip._internal.commands.show import ShowCommand
  15. from pip._internal.commands.install import InstallCommand
  16. from pip._internal.commands.uninstall import UninstallCommand
  17. from pip._internal.commands.wheel import WheelCommand
  18. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  19. if MYPY_CHECK_RUNNING:
  20. from typing import List, Type # noqa: F401
  21. from pip._internal.cli.base_command import Command # noqa: F401
  22. commands_order = [
  23. InstallCommand,
  24. DownloadCommand,
  25. UninstallCommand,
  26. FreezeCommand,
  27. ListCommand,
  28. ShowCommand,
  29. CheckCommand,
  30. ConfigurationCommand,
  31. SearchCommand,
  32. WheelCommand,
  33. HashCommand,
  34. CompletionCommand,
  35. HelpCommand,
  36. ] # type: List[Type[Command]]
  37. commands_dict = {c.name: c for c in commands_order}
  38. def get_summaries(ordered=True):
  39. """Yields sorted (command name, command summary) tuples."""
  40. if ordered:
  41. cmditems = _sort_commands(commands_dict, commands_order)
  42. else:
  43. cmditems = commands_dict.items()
  44. for name, command_class in cmditems:
  45. yield (name, command_class.summary)
  46. def get_similar_commands(name):
  47. """Command name auto-correct."""
  48. from difflib import get_close_matches
  49. name = name.lower()
  50. close_commands = get_close_matches(name, commands_dict.keys())
  51. if close_commands:
  52. return close_commands[0]
  53. else:
  54. return False
  55. def _sort_commands(cmddict, order):
  56. def keyfn(key):
  57. try:
  58. return order.index(key[1])
  59. except ValueError:
  60. # unordered items should come last
  61. return 0xff
  62. return sorted(cmddict.items(), key=keyfn)