This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collect.py
60 lines (47 loc) · 1.48 KB
/
collect.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
import inspect
import json
import sys
def tree():
visited = set()
to_visit = [('tensorflow', __import__('tensorflow'))]
to_insert = []
while len(to_visit) > 0:
m = to_visit[0]
del to_visit[0]
m_name = m[0]
m_val = m[1]
if m_val in visited:
continue
else:
visited.add(m[1])
if hasattr(m_val, '__all__'):
subs = getattr(m_val, '__all__')
else:
subs = dir(m_val)
for sub in subs:
if sub.startswith('_'):
continue
sub_val = getattr(m_val, sub)
sub_type = 'v'
sub_doc = inspect.getdoc(sub_val)
sub_sig = None
full_name = f'{m_name}.{sub}'
if inspect.ismodule(sub_val):
if sub_val.__name__.startswith('tensorflow'):
to_visit.append((full_name, sub_val))
else:
continue
elif inspect.isfunction(sub_val):
sub_type = 'f'
sub_sig = str(inspect.signature(sub_val))
elif inspect.isclass(sub_val):
sub_type = 'c'
to_insert.append({
'name': full_name.replace('tensorflow.', 'tf.'),
'type': sub_type,
'sig': sub_sig,
'doc': sub_doc})
print('exports.apis = ', end='')
json.dump(to_insert, fp=sys.stdout, indent=2)
if __name__ == '__main__':
tree()