1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/pip/commands/__init__.py

87 lines
2.2 KiB
Python
Raw Normal View History

"""
Package containing all pip commands
"""
from __future__ import absolute_import
from pip.commands.completion import CompletionCommand
from pip.commands.download import DownloadCommand
2012-12-06 15:56:46 +01:00
from pip.commands.freeze import FreezeCommand
2015-10-08 05:41:24 +02:00
from pip.commands.hash import HashCommand
2012-12-06 15:56:46 +01:00
from pip.commands.help import HelpCommand
2012-12-16 05:23:55 +01:00
from pip.commands.list import ListCommand
from pip.commands.check import CheckCommand
2012-12-06 15:56:46 +01:00
from pip.commands.search import SearchCommand
from pip.commands.show import ShowCommand
from pip.commands.install import InstallCommand
from pip.commands.uninstall import UninstallCommand
2013-02-03 07:40:30 +01:00
from pip.commands.wheel import WheelCommand
commands_dict = {
2012-12-06 15:56:46 +01:00
CompletionCommand.name: CompletionCommand,
FreezeCommand.name: FreezeCommand,
2015-10-08 05:41:24 +02:00
HashCommand.name: HashCommand,
2012-12-06 15:56:46 +01:00
HelpCommand.name: HelpCommand,
SearchCommand.name: SearchCommand,
ShowCommand.name: ShowCommand,
InstallCommand.name: InstallCommand,
UninstallCommand.name: UninstallCommand,
DownloadCommand.name: DownloadCommand,
2012-12-16 05:23:55 +01:00
ListCommand.name: ListCommand,
CheckCommand.name: CheckCommand,
2013-02-03 07:40:30 +01:00
WheelCommand.name: WheelCommand,
}
commands_order = [
InstallCommand,
DownloadCommand,
UninstallCommand,
FreezeCommand,
ListCommand,
ShowCommand,
CheckCommand,
SearchCommand,
2013-03-16 07:58:27 +01:00
WheelCommand,
2015-10-08 05:41:24 +02:00
HashCommand,
2014-05-10 21:10:28 +02:00
CompletionCommand,
HelpCommand,
]
2016-03-03 23:49:55 +01:00
def get_summaries(ordered=True):
"""Yields sorted (command name, command summary) tuples."""
if ordered:
cmditems = _sort_commands(commands_dict, commands_order)
else:
cmditems = commands_dict.items()
for name, command_class in cmditems:
yield (name, command_class.summary)
def get_similar_commands(name):
"""Command name auto-correct."""
from difflib import get_close_matches
name = name.lower()
close_commands = get_close_matches(name, commands_dict.keys())
if close_commands:
return close_commands[0]
else:
return False
def _sort_commands(cmddict, order):
def keyfn(key):
try:
return order.index(key[1])
except ValueError:
# unordered items should come last
return 0xff
return sorted(cmddict.items(), key=keyfn)