-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
44 lines (35 loc) · 1.36 KB
/
setup.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
"""Module to prepare you python environment."""
import importlib
def run_package(package):
"""Try to run the package just installed."""
try:
globals()[package] = importlib.import_module(package)
print("================================")
except Exception:
print("We can't install {}".format(package))
print("================================")
def install_and_import(package):
"""Install all requiered packages."""
print("checking for {}".format(str(package)))
try:
importlib.import_module(package)
print("{} is already installed".format(package))
except ImportError:
print("We'll install {} before continuing".format(package))
import pip
pip.main(['--trusted-host', 'pypi.python.org', 'install', package])
print("installing {}...".format(package))
finally:
run_package(package)
def get_all_packages():
""""Get all packages in requirement.txt."""
lst_packages = list()
with open('requirement.txt') as fp:
for line in fp:
lst_packages.append(line.split("=")[0].lower())
return lst_packages
if __name__ == '__main__':
lst_install_requires = get_all_packages()
for module in lst_install_requires:
install_and_import(module)
print('You are ready to use the module')