-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscenario.py
58 lines (39 loc) · 1.31 KB
/
scenario.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
#!/usr/bin/env python3
import inspect
import os
import re
DOCS_PATH = os.path.dirname(os.path.abspath(__file__))
import init
from horizons.scenario.actions import ACTIONS
from horizons.scenario.conditions import CONDITIONS
def sphinx_section(text, level):
return '%s\n%s\n' % (text, level * len(text))
def fix_doc(doc):
indent = ' '
if not doc:
return ''
doc = re.sub(r'^\s*@.*$', '', doc, flags=re.MULTILINE)
doc = re.sub(r'#.*$', '', doc, flags=re.MULTILINE)
return indent + doc.replace('\t', indent)
def get_args(func):
args, varargs, _, _ = inspect.getargspec(func)
result = ', '.join(args[1:])
if varargs:
if result:
result += ', \*%s ' % varargs
else:
result = '\*%s' % varargs
return result
def generate():
with open(os.path.join(DOCS_PATH, 'docs/scenario.rst'), 'w') as f:
f.write(sphinx_section('Scenario', '='))
f.write(sphinx_section('Actions', '-'))
for name, func in sorted(ACTIONS.registry.items()):
f.write('.. function:: %s(%s)\n\n' % (name, get_args(func)))
f.write('%s\n\n' % fix_doc(func.__doc__.strip()))
f.write(sphinx_section('Conditions', '-'))
for name, func in sorted(CONDITIONS.registry.items()):
f.write('.. function:: %s(%s)\n\n' % (name, get_args(func)))
f.write('%s\n\n' % fix_doc(func.__doc__.strip()))
if __name__ == '__main__':
generate()