This repository has been archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetup.py
57 lines (46 loc) · 1.71 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
45
46
47
48
49
50
51
52
53
54
55
56
57
import subprocess
import sys
import os.path
from shutil import copyfile
def install(packages):
""" Invokes pip to install list of packages.
Parameters:
packages(list<str>): Packages to install, in requirements.txt format
"""
for package in packages:
try:
subprocess.check_output([sys.executable, "-m", "pip", "install", "--upgrade", package])
except subprocess.CalledProcessError:
print("Caught ProcessError. Trying with --user flag")
subprocess.check_output([sys.executable, "-m", "pip", "install", "--upgrade", "--user", package])
def getListFromFile(file, ignoreStart="#"):
""" Return list of packages to install given a requirements.txt file.
Parameters:
file(str): The requirements.txt file to parse.
ignoreStart(str): Ignore all lines that start with this string (optional).
"""
list = []
with open(file) as handle:
for line in handle.readlines():
if not line.startswith(ignoreStart):
list.append(line)
return list
# Get dependencies for each OS
requirements = getListFromFile("resources/requirements.txt")
windows = getListFromFile("resources/windows.txt", "-r")
linux = getListFromFile("resources/linux.txt", "-r")
mac = getListFromFile("resources/mac.txt", "-r")
# Install dependencies
install(requirements)
if sys.platform == 'win32':
install(windows)
if sys.platform.startswith('linux'):
install(linux)
if sys.platform == 'darwin': # MacOS
install(mac)
# Create config file
if not os.path.isfile("config.ini"):
copyfile("./resources/config_template.ini", "config.ini")
print("Config file created")
# Finished
print("Setup complete")