forked from ltworf/typedload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docgen
executable file
·42 lines (33 loc) · 944 Bytes
/
docgen
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
#!/usr/bin/python3
import sys
import os
pname = sys.argv[1]
fname = os.path.basename(pname).replace('_docgen.md', '')
with open(pname, 'wt') as f:
locals= {}
exec(f'''
import {fname}
doc = {fname}.__doc__
functions = []
classes = []
for name in getattr({fname}, '__all__', []):
try:
item = getattr({fname}, name)
except Exception:
continue
if "<function" in str(item):
functions.append(item)
elif '<class' in str(item):
classes.append(item)
if functions:
doc += '\\nFunctions\\n=========\\n'
for i in functions:
if not i.__doc__: continue
doc += '\\n' + i.__name__ + '\\n' + '-' * len(i.__name__) + '\\n' + i.__doc__
if classes:
doc += '\\nClasses\\n=======\\n'
for i in classes:
if not i.__doc__: continue
doc += '\\n' + i.__name__ + '\\n' + '-' * len(i.__name__) + '\\n' + i.__doc__
''', None, locals)
f.write(locals['doc'])