-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathupdate-fluent-interface.py
More file actions
58 lines (49 loc) · 1.55 KB
/
update-fluent-interface.py
File metadata and controls
58 lines (49 loc) · 1.55 KB
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
import inspect
import re
import sys
from collections import defaultdict
from docarray import Document
all_meth = defaultdict(list)
for f in inspect.getmembers(Document):
if (
callable(f[1])
and not f[1].__name__.startswith('_')
and not f[0].startswith('_')
):
if 'return' in inspect.getfullargspec(f[1]).annotations and str(
inspect.getfullargspec(f[1]).annotations['return']
) in ('~T', 'T'):
module_name = f[1].__qualname__.split('.')[0].replace('Mixin', '')
desc = (
inspect.getdoc(
vars(sys.modules[f[1].__module__])[f[1].__qualname__.split('.')[0]]
)
or ''
)
all_meth[
(
module_name,
desc.strip()
.replace(':class:', '{class}')
.replace(':attr:', '{attr}'),
)
].append(f'{{meth}}`~{f[1].__module__}.{f[1].__qualname__}`')
all_s = []
for k, v in all_meth.items():
all_s.append(f'### {k[0].strip()}')
all_s.append(f'{k[1].strip()}')
for vv in v:
all_s.append(f'- {vv}')
all_s.append('\n')
doc_md = '../docs/fundamentals/document/fluent-interface.md'
text = '\n'.join(all_s)
with open(doc_md) as fp:
_old = fp.read()
_new = re.sub(
r'(<!-- fluent-interface-start -->\s*?\n).*(\n\s*?<!-- fluent-interface-end -->)',
rf'\g<1>{text}\g<2>',
_old,
flags=re.DOTALL,
)
with open(doc_md, 'w') as fp:
fp.write(_new)