-
Notifications
You must be signed in to change notification settings - Fork 20
/
install
executable file
·81 lines (60 loc) · 2.37 KB
/
install
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
#!/usr/bin/env python3
import os
import sys
import argparse
import subprocess
def run(command):
subprocess.check_call(['/bin/bash', '-c', command],
stdout=sys.stdout, stderr=sys.stderr)
def register_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--offline-install-path', help='The dir path to install pip packages from.')
parser.add_argument('--no-link', action='store_true',
help='Do not remove or create symlink')
parser.add_argument('--dev', action='store_true',
help='Install dev requirements in addition to common requirements')
return parser.parse_args()
def _create_sym_link():
# symlink to run
ln_cmd = 'ln -sfF {0}/run /usr/local/bin/manof'.format(os.getcwd())
# first try without sudo, then with
try:
run(ln_cmd)
except subprocess.CalledProcessError:
run('sudo {0}'.format(ln_cmd))
def _install_venv():
run('rm -rf venv')
run('python3 -m venv venv --without-pip')
python_version_specific = ''
if sys.version_info.minor== 7:
python_version_specific = 'pip/3.7/'
run('source venv/bin/activate && curl https://bootstrap.pypa.io/{0}get-pip.py | python'.format(python_version_specific))
def main():
args = register_arguments()
if args.offline_install_path is None:
local_pip_packages = ''
else:
local_pip_packages = '--no-index --find-links=file:{}'.format(
args.offline_install_path)
retval = 0
try:
requirements_file = 'requirements.txt'
if args.dev:
requirements_file = 'requirements_all.txt'
# create venv, activate it and install requirements to it
# (from a local dir if it exists)
# "python -m pip install" instead of "pip install" handles a pip
# issue where it fails in a long-named dir
_install_venv()
run('source venv/bin/activate && '
'python -m pip install {0} incremental && '.format(local_pip_packages) +
'python -m pip install {0} -r {1}'.format(local_pip_packages, requirements_file))
if not args.no_link:
_create_sym_link()
except subprocess.CalledProcessError as e:
retval = e.returncode
else:
print('Installation complete. Enjoy your manof!')
sys.exit(retval)
if __name__ == '__main__':
main()