pip/pip/commands/__init__.py

78 lines
2.0 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.configuration import ConfigurationCommand
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
2017-06-15 21:51:33 +02:00
if False:
from typing import List, Type
from pip.basecommand import Command
commands_order = [
InstallCommand,
DownloadCommand,
UninstallCommand,
FreezeCommand,
ListCommand,
ShowCommand,
CheckCommand,
ConfigurationCommand,
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,
2017-06-15 21:51:33 +02:00
] # type: List[Type[Command]]
commands_dict = {c.name: c for c in commands_order}
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)