No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

80 líneas
2.0 KiB

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