Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/helper_scripts/parse_cb_list.py
928 views
1
import inspect
2
from textwrap import TextWrapper
3
4
import yt
5
6
ds = yt.load("RD0005-mine/RedshiftOutput0005")
7
8
output = open("source/visualizing/_cb_docstrings.inc", "w")
9
10
template = """
11
12
.. function:: %(clsname)s%(sig)s:
13
14
(This is a proxy for :class:`~%(clsproxy)s`.)
15
16
%(docstring)s
17
18
"""
19
20
tw = TextWrapper(initial_indent=" ", subsequent_indent=" ", width=60)
21
22
23
def write_docstring(f, name, cls):
24
if not hasattr(cls, "_type_name") or cls._type_name is None:
25
return
26
for clsi in inspect.getmro(cls):
27
docstring = inspect.getdoc(clsi.__init__)
28
if docstring is not None:
29
break
30
clsname = cls._type_name
31
sig = inspect.formatargspec(*inspect.getargspec(cls.__init__))
32
sig = sig.replace("**kwargs", "**field_parameters")
33
clsproxy = f"yt.visualization.plot_modifications.{cls.__name__}"
34
# docstring = "\n".join([" %s" % line for line in docstring.split("\n")])
35
# print(docstring)
36
f.write(
37
template
38
% dict(
39
clsname=clsname,
40
sig=sig,
41
clsproxy=clsproxy,
42
docstring="\n".join(tw.wrap(docstring)),
43
)
44
)
45
# docstring = docstring))
46
47
48
for n, c in sorted(yt.visualization.api.callback_registry.items()):
49
write_docstring(output, n, c)
50
print(f".. autoclass:: yt.visualization.plot_modifications.{n}")
51
print(" :members:")
52
print()
53
54