OSDN Git Service

PEP8対応
[stux/ultron.git] / venv / Lib / site-packages / pip / commands / __init__.py
1 """
2 Package containing all pip commands
3 """
4 from __future__ import absolute_import
5
6 from pip.commands.completion import CompletionCommand
7 from pip.commands.download import DownloadCommand
8 from pip.commands.freeze import FreezeCommand
9 from pip.commands.hash import HashCommand
10 from pip.commands.help import HelpCommand
11 from pip.commands.list import ListCommand
12 from pip.commands.check import CheckCommand
13 from pip.commands.search import SearchCommand
14 from pip.commands.show import ShowCommand
15 from pip.commands.install import InstallCommand
16 from pip.commands.uninstall import UninstallCommand
17 from pip.commands.wheel import WheelCommand
18
19
20 commands_dict = {
21     CompletionCommand.name: CompletionCommand,
22     FreezeCommand.name: FreezeCommand,
23     HashCommand.name: HashCommand,
24     HelpCommand.name: HelpCommand,
25     SearchCommand.name: SearchCommand,
26     ShowCommand.name: ShowCommand,
27     InstallCommand.name: InstallCommand,
28     UninstallCommand.name: UninstallCommand,
29     DownloadCommand.name: DownloadCommand,
30     ListCommand.name: ListCommand,
31     CheckCommand.name: CheckCommand,
32     WheelCommand.name: WheelCommand,
33 }
34
35
36 commands_order = [
37     InstallCommand,
38     DownloadCommand,
39     UninstallCommand,
40     FreezeCommand,
41     ListCommand,
42     ShowCommand,
43     CheckCommand,
44     SearchCommand,
45     WheelCommand,
46     HashCommand,
47     CompletionCommand,
48     HelpCommand,
49 ]
50
51
52 def get_summaries(ordered=True):
53     """Yields sorted (command name, command summary) tuples."""
54
55     if ordered:
56         cmditems = _sort_commands(commands_dict, commands_order)
57     else:
58         cmditems = commands_dict.items()
59
60     for name, command_class in cmditems:
61         yield (name, command_class.summary)
62
63
64 def get_similar_commands(name):
65     """Command name auto-correct."""
66     from difflib import get_close_matches
67
68     name = name.lower()
69
70     close_commands = get_close_matches(name, commands_dict.keys())
71
72     if close_commands:
73         return close_commands[0]
74     else:
75         return False
76
77
78 def _sort_commands(cmddict, order):
79     def keyfn(key):
80         try:
81             return order.index(key[1])
82         except ValueError:
83             # unordered items should come last
84             return 0xff
85
86     return sorted(cmddict.items(), key=keyfn)