2012-11-10 05:05:38 +01:00
|
|
|
"""
|
|
|
|
Package containing all pip commands
|
|
|
|
"""
|
2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
2012-11-10 05:05:38 +01:00
|
|
|
|
|
|
|
from pip.commands.completion import CompletionCommand
|
2017-01-18 04:00:02 +01:00
|
|
|
from pip.commands.configuration import ConfigurationCommand
|
2015-07-29 22:25:13 +02:00
|
|
|
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
|
2013-06-19 14:13:06 +02:00
|
|
|
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
|
2012-11-10 05:05:38 +01:00
|
|
|
|
2017-06-15 21:51:33 +02:00
|
|
|
if False:
|
|
|
|
from typing import List, Type
|
|
|
|
from pip.basecommand import Command
|
|
|
|
|
2013-02-12 22:23:40 +01:00
|
|
|
commands_order = [
|
|
|
|
InstallCommand,
|
2015-07-29 22:25:13 +02:00
|
|
|
DownloadCommand,
|
2013-02-12 22:23:40 +01:00
|
|
|
UninstallCommand,
|
|
|
|
FreezeCommand,
|
|
|
|
ListCommand,
|
|
|
|
ShowCommand,
|
2013-06-19 14:13:06 +02:00
|
|
|
CheckCommand,
|
2017-01-18 04:00:02 +01:00
|
|
|
ConfigurationCommand,
|
2013-02-12 22:23:40 +01:00
|
|
|
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,
|
2013-02-12 22:23:40 +01:00
|
|
|
HelpCommand,
|
2017-06-15 21:51:33 +02:00
|
|
|
] # type: List[Type[Command]]
|
2012-11-10 05:05:38 +01:00
|
|
|
|
2017-05-13 12:26:22 +02:00
|
|
|
commands_dict = {c.name: c for c in commands_order}
|
|
|
|
|
2013-02-12 22:23:40 +01:00
|
|
|
|
2016-03-03 23:49:55 +01:00
|
|
|
def get_summaries(ordered=True):
|
2013-02-12 22:23:40 +01:00
|
|
|
"""Yields sorted (command name, command summary) tuples."""
|
|
|
|
|
|
|
|
if ordered:
|
2014-12-02 16:47:36 +01:00
|
|
|
cmditems = _sort_commands(commands_dict, commands_order)
|
2013-02-12 22:23:40 +01:00
|
|
|
else:
|
2014-12-02 16:47:36 +01:00
|
|
|
cmditems = commands_dict.items()
|
2013-02-12 22:23:40 +01:00
|
|
|
|
|
|
|
for name, command_class in cmditems:
|
|
|
|
yield (name, command_class.summary)
|
2012-11-10 05:05:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_similar_commands(name):
|
|
|
|
"""Command name auto-correct."""
|
|
|
|
from difflib import get_close_matches
|
|
|
|
|
2014-04-15 23:47:15 +02:00
|
|
|
name = name.lower()
|
|
|
|
|
2014-12-02 16:47:36 +01:00
|
|
|
close_commands = get_close_matches(name, commands_dict.keys())
|
2012-11-10 05:05:38 +01:00
|
|
|
|
|
|
|
if close_commands:
|
2014-04-15 23:47:15 +02:00
|
|
|
return close_commands[0]
|
2012-11-10 05:05:38 +01:00
|
|
|
else:
|
2014-04-15 23:47:15 +02:00
|
|
|
return False
|
2013-02-12 22:23:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
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)
|