-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.py
97 lines (74 loc) · 3.35 KB
/
build.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from shutil import which, rmtree
import platform
import sys
import os
def install():
if which("poetry") is None:
if input("Poetry is missing, would you like to install it? [y/n]").lower() in ["y", "yes"]:
print("Installing poetry...")
if platform.system() == "Windows":
os.system("powershell '(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -'")
elif platform.system() in ["Linux", "Darwin"]:
os.system("curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -")
else:
print("Unkonwn platform, please install poetry manually.")
print("Please restart your terminal and verify that poetry is installed before running this script again.")
else:
os.system("poetry install")
def lint():
print("Running ruff for linting...")
os.system(f"poetry run ruff TrackingBackend{os.path.sep}")
print("-" * 80)
print("Running black for code formatting...")
os.system(f"poetry run black TrackingBackend{os.path.sep}")
print("-" * 80)
print("Running mypy for type checking...")
os.system(f"poetry run mypy --ignore-missing-imports --check-untyped-defs TrackingBackend{os.path.sep}")
print("-" * 80)
print("Running pytest for unit testing...")
os.system(f"poetry run pytest TrackingBackend{os.path.sep}")
print("-" * 80)
def clean():
print("Cleaning build and cache directories...")
for folder in ["build", "dist", ".ruff_cache", ".pytest_cache", ".mypy_cache"]:
if os.path.exists(folder):
print(f"Deleting {folder}")
rmtree(folder)
for root, dirs, _ in os.walk(".", topdown=False):
for name in dirs:
if name == "__pycache__":
print(f"Deleting {os.path.join(root, name)}")
rmtree(os.path.join(root, name))
def build():
os.system("poetry run pyinstaller ETVR.spec TrackingBackend/main.py")
def profile():
os.chdir(f"{os.path.dirname(os.path.abspath(__file__))}{os.path.sep}TrackingBackend")
try:
os.system("poetry run viztracer main.py")
except KeyboardInterrupt:
exit(0)
def run():
os.chdir(f"{os.path.dirname(os.path.abspath(__file__))}{os.path.sep}TrackingBackend")
os.system("poetry run uvicorn --factory main:setup_app --reload --port 8000")
def emulate():
print("This is still a work in progress, please check back later!")
def help():
print("Usage: python build.py [OPTIONS]")
print("Options:")
print("lint Run the linter, formatter, type checker, and unit tester")
print("run Run the ETVR backend server in development mode")
print("build Build and bundle the project with pyinstaller")
print("profile Run the ETVR backend server with viztracer")
print("emulate Start the algorithm debugger and emulator")
print("install Install project dependencies")
print("clean Clean intermediate files")
print("help Show this help message and exit")
if __name__ == "__main__":
if which("poetry") is None:
install()
else:
# i dont want to use argparse so we are doing this the sketchy way
try:
eval(sys.argv[1].lower() + "()")
except IndexError:
help()