-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpythondoc.py
48 lines (39 loc) · 1.52 KB
/
pythondoc.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
import sys
from types import ModuleType
import pdoc
import pdoc.cli
import constriction
constriction.__all__ = constriction.constriction.__all__
del constriction.constriction
context = pdoc.Context()
pdoc.link_inheritance(context)
def pdocify(mod, prefix=''):
pdoc_mod = pdoc.Module(mod)
prefix = prefix + pdoc_mod.name + '.'
# Remove documentation of deprecated methods.
for child_name in pdoc_mod.doc:
child = pdoc_mod.doc[child_name]
try:
grandchild_names = list(child.doc.keys()) # so we can modify the dictionary while iterating over it.
except:
continue
for grandchild_name in grandchild_names:
grandchild = child.doc[grandchild_name]
grandchild_doc = grandchild.docstring
if grandchild_doc is not None and grandchild_doc[:16] == '.. deprecated:: ':
del child.doc[grandchild_name]
if hasattr(mod, '__all__'):
for child_name in mod.__all__:
child = getattr(mod, child_name)
if isinstance(child, ModuleType):
child = pdocify(child, prefix=prefix)
child.supermodule = pdoc_mod
child.name = prefix + child_name
pdoc_mod.doc[prefix + child_name] = child
return pdoc_mod
if __name__ == '__main__':
pdoc.cli.args.output_dir = sys.argv[1]
pdoc.cli.args.force = True
constriction_mod = pdocify(constriction)
del constriction_mod.doc['constriction']
pdoc.cli.recursive_write_files(constriction_mod, '.html')