-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.py
124 lines (100 loc) · 3.03 KB
/
manage.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
import sys
import os
def print_green(s):
GREEN = "\033[92m"
ENDC = "\033[0m"
print(f"{GREEN}{s}{ENDC}")
def run_command(cmd):
print_green(cmd)
os.system(cmd)
def get_command_output(cmd):
return os.popen(cmd).read()
def dev(extra_args):
"""
This command starts up a development environment.
The development environment is started through docker-compose
and is visible at http://localhost
"""
command = f"docker-compose -f docker-compose.yml \
up --build --renew-anon-volumes"
run_command(command + extra_args)
def test(extra_args):
"""
This command runs the tests within docker
and then exits.
"""
command = """\
docker build -t workflow-runner-testing -f Dockerfile.test .
docker run -it workflow-runner-testing\
"""
run_command(command + extra_args)
REQUIREMENTS_FILES = {
"requirements.txt": "requirements-lock.txt",
"requirements-test.txt": "requirements-test-lock.txt",
}
def lock(extra_args):
"""
Write lockfiles without upgrading dependencies
"""
for src, locked in REQUIREMENTS_FILES.items():
command = f"""\
docker run -v $(pwd):/app python:3.9 \
/bin/bash -c "
# Install lockfile first so that we get the
# currently installed versions of dependencies
pip install -r /app/{locked} &&
pip install -r /app/{src} &&
# Write lockfile
pip freeze > /app/{locked}
"
"""
run_command(command)
def verify_locked(extra_args):
"""
Verify that the lockfile is up-to-date
"""
for src, locked in REQUIREMENTS_FILES.items():
dependencies = get_command_output(
f"""\
docker run -v $(pwd):/app python:3.9 \
/bin/bash -c "
pip install -qqq -r /app/{locked} &&
pip install -qqq -r /app/{src} &&
pip freeze
"
"""
)
lock_dependencies = get_command_output(
f"""\
docker run -v $(pwd):/app python:3.9 \
/bin/bash -c "
pip install -qqq -r /app/{locked} &&
pip freeze
"
"""
)
if dependencies != lock_dependencies:
sys.exit(f"Lock file {locked} not up-to-date, please run ./manage.py lock")
def upgrade(extra_args):
"""
Upgrade all dependencies
"""
for src, locked in REQUIREMENTS_FILES.items():
command = f"""\
docker run -v $(pwd):/app python:3.9 \
/bin/bash -c "
# Install dependencies, getting latest version
pip install -r /app/{src} &&
# Write lockfile
pip freeze > /app/{locked}
"
"""
run_command(command)
def main():
command = sys.argv[1]
command_func = globals()[command]
extra_args = " " + " ".join(sys.argv[2:])
command_func(extra_args)
if __name__ == "__main__":
main()