-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path__main__.py
More file actions
96 lines (86 loc) · 2.86 KB
/
Copy path__main__.py
File metadata and controls
96 lines (86 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import itertools
import os
import subprocess
import site
import sys
from plover_plugins_manager import global_registry
from plover_plugins_manager import local_registry
from plover_plugins_manager.utils import running_under_virtualenv
def list_plugins(freeze=False):
installed_plugins = local_registry.list_plugins()
if freeze:
available_plugins = {}
else:
available_plugins = global_registry.list_plugins()
for name, installed, available in sorted(
(name,
installed_plugins.get(name, []),
available_plugins.get(name, []))
for name in set(itertools.chain(installed_plugins,
available_plugins))
):
latest = available[-1] if available else None
current = installed[-1] if installed else None
info = latest or current
if freeze:
if current:
print('%s==%s' % (current.name, current.version))
continue
print('%s (%s) - %s' % (info.name, info.version, info.summary))
if current:
print(' INSTALLED: %s' % current.version)
if latest:
print(' LATEST: %s' % latest.version)
def pip(args, stdin=None, stdout=None, stderr=None, **kwargs):
cmd = [sys.executable, '-m',
'plover_plugins_manager.pip_wrapper',
'--disable-pip-version-check']
env = dict(os.environ)
# Make sure user plugins are handled
# even if user site is not enabled.
if not running_under_virtualenv() and not site.ENABLE_USER_SITE:
pypath = env.get('PYTHONPATH')
if pypath is None:
pypath = []
else:
pypath = pypath.split(os.pathsep)
pypath.insert(0, site.USER_SITE)
env['PYTHONPATH'] = os.pathsep.join(pypath)
command = args.pop(0)
if command == 'check':
cmd.append('check')
elif command == 'install':
cmd.extend((
'install',
'--upgrade-strategy=only-if-needed',
))
if not running_under_virtualenv():
cmd.append('--user')
elif command == 'uninstall':
cmd.append('uninstall')
elif command == 'list':
cmd.extend((
'list',
'--format=columns',
))
else:
raise ValueError('invalid command: %s' % command)
cmd.extend(args)
return subprocess.Popen(cmd, env=env, stdin=stdin,
stdout=stdout, stderr=stderr,
**kwargs)
def main(args=None):
if args is None:
args = sys.argv[1:]
if args[0] == 'list_plugins':
assert len(args) <= 2
if len(args) > 1:
assert args[1] == '--freeze'
freeze = True
else:
freeze = False
sys.exit(list_plugins(freeze=freeze))
proc = pip(args)
sys.exit(proc.wait())
if __name__ == '__main__':
main()