-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
executable file
·77 lines (57 loc) · 2.38 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
#!/usr/bin/env python3.7
from subprocess import run
from pathlib import Path
import shutil, os, os.path, sys
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
SHELL = True if os.name == 'nt' else False
def clean():
static_dir = os.path.join(ROOT_DIR, 'static')
if os.path.exists(static_dir):
print ("Deleting " + static_dir)
shutil.rmtree(static_dir)
def install():
run(['npm','install'], check=True, cwd='frontend', shell=SHELL)
run(['python','-m','pip','install','-r','requirements.txt'], check=True, shell=SHELL)
def build():
run(['npx','browserslist@latest','--update-db','-y'], check=False, cwd='frontend', shell=SHELL)
run(['npm','run','build'], check=True, cwd='frontend', shell=SHELL)
run(['python','manage.py','collectstatic'], check=True, shell=SHELL)
run(['python','manage.py','check'], check=True, shell=SHELL)
def migratedb():
run(['python','manage.py','makemigrations'], check=True, shell=SHELL)
run(['python','manage.py','migrate'], check=True, shell=SHELL)
def test():
print("\n == NPM TEST")
testEnv = os.environ.update({'CI':'true'})
run(['npm','run','test'], check=True, env=testEnv, cwd='frontend', shell=SHELL)
# doesn't pass yet, so skip it
#print("\n == PYTHON TEST")
#run(['python','manage.py','test', '--debug-mode'], check=True, env=testEnv, shell=SHELL)
def reload():
'''reload web app at pythonanywhere.com'''
paths = [Path('/var/www/macke_eu_pythonanywhere_com_wsgi.py'),
Path('/var/www/test-macke_eu_pythonanywhere_com_wsgi.py')]
found = False
for path in paths:
if path.exists():
print(f"Touching {path}")
path.touch()
found = True
else:
print(f"Ignoring WSGI file {path} as it doesn't exist here.")
if found:
run(['python','manage.py','check', '--deploy'], shell=SHELL)
this_module = sys.modules[__name__]
if __name__ == '__main__':
print("Working in " + ROOT_DIR + " ...")
os.chdir(ROOT_DIR)
tasks = ['install', 'clean', 'build', 'migratedb', 'test', 'reload']
if '--help' in sys.argv:
print("build.py [task(s)] (" + tasks + ")")
sys.exit(0)
if len(sys.argv) > 1:
tasks = [f for f in sys.argv[1:]]
for f in [getattr(this_module, f) for f in tasks]:
print ("\n === {} ===\n".format(f.__name__))
f()
print ("SUCCESS!")