-
Notifications
You must be signed in to change notification settings - Fork 43
/
installer.py
58 lines (45 loc) · 1.39 KB
/
installer.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
import os
import sys
import subprocess
clear = lambda: os.system('cls')
def install(package: str):
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
def is_installed(package: str):
try:
__import__(package)
return True
except ImportError:
return False
except Exception as e:
print(f'Unexpected error: {e} while checking if {package} is installed')
return True
def get_pending_packages():
pending = []
with open('requirements.txt', 'rt') as f:
requirements = f.read().splitlines()
for package in requirements:
if package and not is_installed(package):
pending.append(package)
return pending
def setup():
pending = get_pending_packages()
if not pending:
return print('All packages are installed')
print(f'{len(pending)} missing packages.\n\tWould you like to install them? (y/n)')
if input().lower() == 'y':
for package in pending:
print(f'Installing {package}...')
install(package)
print('Installation complete')
else:
print('Installation cancelled')
def main():
try:
clear()
setup()
except KeyboardInterrupt:
print('Installation cancelled by user')
if __name__ == '__main__':
main()
else:
print("Installer is not allowed to be ran, by other programs!")