forked from compas-dev/compas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_rst.py
152 lines (118 loc) · 3.41 KB
/
write_rst.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# from pathlib import Path
from compas import datastructures as module
TPL = """
********************************************************************************
{currentmodule}
********************************************************************************
.. currentmodule:: {currentmodule}
.. rst-class:: lead
{lead}
{sections}
"""
SECTION = """
{title}
{line}
{summary}
.. autosummary::
:toctree: generated/
:nosignatures:
{items}
"""
__newall__ = {
"functions": [],
"classes": [],
"errors": [],
"numpy": [],
"pluggables": [],
"plugins": [],
}
for name in module.__all__:
obj = getattr(module, name)
if name.endswith("_numpy"):
__newall__["numpy"].append(name)
continue
if issubclass(type(obj), Exception):
__newall__["errors"].append(name)
continue
if hasattr(obj, "__pluggable__"):
__newall__["pluggables"].append(name)
continue
if hasattr(obj, "__plugin__"):
__newall__["plugins"].append(name)
continue
if isinstance(obj, type):
__newall__["classes"].append(name)
else:
__newall__["functions"].append(name)
currentmodule = module.__name__
lead = module.__doc__
classes = ""
for name in sorted(__newall__["classes"]):
classes += " {name}\n".format(name=name)
if classes:
classes = SECTION.format(
title="Classes",
line="=" * len("Classes"),
summary="",
items=classes,
)
errors = ""
for name in sorted(__newall__["errors"]):
errors += " {name}\n".format(name=name)
if errors:
errors = SECTION.format(
title="Exceptions",
line="=" * len("Exceptions"),
summary="",
items=errors,
)
functions = ""
for name in sorted(__newall__["functions"]):
functions += " {name}\n".format(name=name)
if functions:
functions = SECTION.format(
title="Functions",
line="=" * len("Functions"),
summary="",
items=functions,
)
numpy = ""
for name in sorted(__newall__["numpy"]):
numpy += " {name}\n".format(name=name)
if numpy:
numpy = SECTION.format(
title="Functions using Numpy",
line="=" * len("Functions using Numpy"),
summary="In environments where numpy is not available, these functions can still be accessed through RPC.",
items=numpy,
)
pluggables = ""
for name in sorted(__newall__["pluggables"]):
pluggables += " {name}\n".format(name=name)
if pluggables:
pluggables = SECTION.format(
title="Pluggables",
line="=" * len("Pluggables"),
summary="Pluggables are functions that don't have an actual implementation, but receive an implementation from a plugin.",
items=pluggables,
)
plugins = ""
for name in sorted(__newall__["plugins"]):
plugins += " {name}\n".format(name=name)
if plugins:
plugins = SECTION.format(
title="Plugins",
line="=" * len("Plugins"),
summary="Plugins provide implementations for pluggables. You can use the plugin directly, or through the pluggable.",
items=plugins,
)
sections = "".join([classes, errors, functions, numpy, pluggables, plugins])
# docs = Path(__file__).parent
with open("/Users/vanmelet/Code/compas/docs/api/{name}.rst".format(name=module.__name__), "w") as f:
f.write(
TPL.format(
currentmodule=currentmodule,
lead=lead,
sections=sections,
)
)