-
Notifications
You must be signed in to change notification settings - Fork 15
/
regenerate-tool-contracts.py
executable file
·87 lines (67 loc) · 2.58 KB
/
regenerate-tool-contracts.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
#!/usr/bin/env python
"""
# This is for pbsmrtpipe (and subdependency, pbcommand) ONLY. DO NOT put random
# SA# tools in here. They should NOT be assumed to be installed.
"""
import os
import shlex
import sys
import subprocess
import itertools
import multiprocessing
from pbcommand.engine import run_cmd
_EMIT = '--emit-tool-contract'
TC_DIR = 'pbsmrtpipe/registered_tool_contracts'
SA3_TC_DIR = 'pbsmrtpipe/registered_tool_contracts_sa3'
TASKS_ROOT = 'pbsmrtpipe/tools_dev'
PBCOMMAND_TCS = ('dev_txt_app',
'dev_app',
'dev_gather_fasta_app',
'dev_scatter_fasta_app')
def _to_tc_cmd(input_module, output_file):
return "python -m {i} {e} > {o}".format(i=input_module, e=_EMIT, o=output_file)
def _to_registry_cmd(input_file):
return "python -m {i} emit-tool-contracts -o {o}".format(i=input_file, o=TC_DIR)
def create_all_pbsmrtpipe_tcs(root_dir, output_dir):
cmds = []
for file_name in os.listdir(root_dir):
if not file_name.startswith('__') and not file_name.startswith('.'):
name = os.path.splitext(file_name)[0]
file_name = 'pbsmrtpipe.tools_dev.' + name + "_tool_contract.json"
output_file = os.path.join(output_dir, file_name)
module_name = 'pbsmrtpipe.tools_dev.' + name
cmd = _to_tc_cmd(module_name, output_file)
cmds.append(cmd)
return cmds
def quick_registry(output_dir):
cmds = []
x = cmds.append
x('python -m pbsmrtpipe.pb_tasks.dev emit-tool-contracts -o {o}'.format(o=output_dir))
x('python -m pbcommand.cli.examples.dev_quick_hello_world emit-tool-contracts -o {o}'.format(o=output_dir))
return cmds
def create_pbcommand_tcs(output_dir):
cmds = []
for i in PBCOMMAND_TCS:
module_name = 'pbcommand.cli.examples.' + i
output_name = 'dev_pbcommand_{i}_tool_contract.json'.format(i=i)
cmd = _to_tc_cmd(module_name, os.path.join(output_dir, output_name))
cmds.append(cmd)
return cmds
def _run_cmd(cmd):
print cmd
result = run_cmd(cmd, sys.stdout, sys.stderr)
if result.exit_code != 0:
print result
raise ValueError("Failed to generate TC from {c}".format(c=cmd))
return result
def create_all():
to_cmds = [#create_all_pbsmrtpipe_tcs(TASKS_ROOT, TC_DIR),
create_pbcommand_tcs(TC_DIR),
quick_registry(TC_DIR),
]
cmds = itertools.chain(*to_cmds)
p = multiprocessing.Pool(min(multiprocessing.cpu_count(), 4))
results = p.map(_run_cmd, cmds)
return 0
if __name__ == '__main__':
sys.exit(create_all())