forked from ThoughtWorksInc/CD4ML-Scenarios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_python_script.py
52 lines (38 loc) · 1.39 KB
/
run_python_script.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
import cProfile
import sys
script_names = ["pipeline", "acceptance"]
script_names_str = script_names.__repr__()
def run_python_script(script_name, *args, **kwargs):
if 'profiler' in kwargs:
use_profiler = True
else:
use_profiler = False
if script_name == 'show':
print("\nAvailable scripts\n----------------")
for s in script_names:
print(s)
exit(0)
if profiler:
print("running with profiler")
if script_name == "pipeline":
from scripts import pipeline as script
elif script_name == "acceptance":
from scripts import acceptance as script
else:
message = "Error, script_name (%s) must be one of %s" % (script_name,
script_names_str)
raise ValueError(message)
if profiler:
command = "script.main(*args)"
filename = "%s.prof" % script_name
cProfile.runctx(command, None, locals(), filename=filename)
print("To see profiler result, run:\nsnakeviz %s" % filename)
else:
script.main(*args)
if __name__ == "__main__":
profiler = ' -p' in ' '.join(sys.argv)
script = sys.argv[1]
arguments = sys.argv[2:]
# remove the profile flag now that profiler is on
arguments = [i for i in arguments if i != '-p']
run_python_script(script, arguments, profiler=profiler)