-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_deps.py
executable file
·68 lines (54 loc) · 1.91 KB
/
install_deps.py
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
#!/usr/bin/env python
"""
Install the packages you have listed in the requirements file you input as
first argument.
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import sys
import fileinput
import subprocess
import logging
import uuid
from pip.req import parse_requirements
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
def get_requirements(*args):
"""Parse all requirements files given and return a list of the dependencies"""
if len(args) < 1:
raise ValueError('Some arguments were expected, but received {} arguments.'.format(len(args)))
install_deps = []
try:
for fpath in args:
install_deps.extend([str(d.req) for d in parse_requirements(fpath, session=uuid.uuid1())])
except:
log.exception('Error reading {} file looking for dependencies.'.format(fpath))
raise
return [dep for dep in install_deps if dep != 'None']
if __name__ == '__main__':
if not len(sys.argv):
log.error('Usage: ./install_deps.py <list of requirements files>')
exit(-1)
req_filepaths = []
for line in fileinput.input():
req_filepaths = sys.argv[1:]
try:
deps = get_requirements(*req_filepaths)
except:
log.exception('Error reading files {}.'.format(req_filepaths))
exit(-1)
else:
if not len(deps):
log.error('After parsing the given files: {}, could not get any '
'valid requirement.'.format(req_filepaths))
exit(-1)
try:
for dep_name in deps:
cmd = "pip install '{0}'".format(dep_name)
print('#', cmd)
subprocess.check_call(cmd, shell=True)
except:
log.exception('Error installing {}'.format(dep_name))
exit(-1)
else:
log.info('Requirements: {} successfully installed.'.format(deps))