-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
82 lines (65 loc) · 2.53 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import os
import subprocess
import sys
GIT_ROOT = os.path.dirname(os.path.realpath(__file__))
def run(cmd, echo=False):
proc = subprocess.Popen(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, err = proc.communicate()
out = out.decode('utf-8').strip()
err = err.decode('utf-8').strip()
if echo:
print('\x1b[90m ' + out.replace('\n', '\n ') + '\x1b[0m')
print('\x1b[31m ' + err.replace('\n', '\n ') + '\x1b[0m')
return out
def find_python():
if sys.version_info.major >= 3 and sys.version_info.minor >= 11:
return sys.executable
else:
print("Looking for Python 3.11...")
exes = ["py -3.11", "py", "python3.11", "python", "python3"]
for exe in exes:
try:
print(f"Trying '{exe}'")
version = run(exe + " --version")
if not version.startswith("Python 3"):
continue
version = version[7:].split('.')
major = int(version[0])
minor = int(version[1])
if (major >= 3 and minor >= 11):
return exe
except FileNotFoundError:
continue
print("Could not find Python 3.11 or newer, please install it.")
exit(1)
py = find_python()
installed_python_modules = run(f"{py} -m pip list")
if "poetry " not in installed_python_modules:
print("Installing poetry...")
run(py + " -m pip install poetry")
os.chdir(os.path.join(GIT_ROOT, "backend"))
print("backend: Running 'poetry install'...")
run(f"{py} -m poetry --quiet install", echo=True)
py = f"{py} -m poetry --quiet run python"
print("backend: Running 'manage.py migrate'...")
migrate = run(f"{py} manage.py migrate", echo=True)
print("backend: Running 'manage.py makemigrations'...")
print("If you get stuck here, it may need user input,\nrun it on the command line as 'poetry --quiet run python manage.py makemigrations' in backend/")
run(f"{py} manage.py makemigrations", echo=True)
if "re-run 'manage.py migrate'" in migrate: # Ok
print("backend: Running 'manage.py migrate'...")
run(f"{py} manage.py migrate", echo=True)
if len(sys.argv) > 1 and sys.argv[1] == "admin":
print("Running 'manage.py createsuperuser'...")
os.system(f"{py} manage.py createsuperuser")
exit(0)
os.chdir(os.path.join(GIT_ROOT, "frontend"))
print("frontend: Running 'npm install'...")
run("npm install", echo=True)
print("Okay, now run 'node run.js'")