Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/helper_scripts/parse_dq_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/_dq_docstrings.inc", "w")
9
10
template = """
11
12
.. function:: %(funcname)s%(sig)s:
13
14
(This is a proxy for :func:`~%(funcproxy)s`.)
15
%(docstring)s
16
17
"""
18
19
tw = TextWrapper(initial_indent=" ", subsequent_indent=" ", width=60)
20
21
22
def write_docstring(f, name, func):
23
docstring = inspect.getdoc(func)
24
funcname = name
25
sig = inspect.formatargspec(*inspect.getargspec(func))
26
sig = sig.replace("data, ", "")
27
sig = sig.replace("(data)", "()")
28
funcproxy = f"yt.data_objects.derived_quantities.{func.__name__}"
29
docstring = "\n".join(" %s" % line for line in docstring.split("\n"))
30
f.write(
31
template
32
% dict(funcname=funcname, sig=sig, funcproxy=funcproxy, docstring=docstring)
33
)
34
# docstring = "\n".join(tw.wrap(docstring))))
35
36
37
dd = ds.all_data()
38
for n, func in sorted(dd.quantities.functions.items()):
39
print(n, func)
40
write_docstring(output, n, func[1])
41
42