Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/helper_scripts/parse_object_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/analyzing/_obj_docstrings.inc", "w")
9
10
template = """
11
12
.. class:: %(clsname)s%(sig)s:
13
14
For more information, see :ref:`%(docstring)s`
15
(This is a proxy for :class:`~%(clsproxy)sBase`.)
16
"""
17
18
tw = TextWrapper(initial_indent=" ", subsequent_indent=" ", width=60)
19
20
21
def write_docstring(f, name, cls):
22
for clsi in inspect.getmro(cls):
23
docstring = inspect.getdoc(clsi.__init__)
24
if docstring is not None:
25
break
26
clsname = name
27
sig = inspect.formatargspec(*inspect.getargspec(cls.__init__))
28
sig = sig.replace("**kwargs", "**field_parameters")
29
clsproxy = f"yt.data_objects.data_containers.{cls.__name__}"
30
f.write(
31
template
32
% dict(
33
clsname=clsname, sig=sig, clsproxy=clsproxy, docstring="physical-object-api"
34
)
35
)
36
37
38
for n, c in sorted(ds.__dict__.items()):
39
if hasattr(c, "_con_args"):
40
print(n)
41
write_docstring(output, n, c)
42
43