File: parse_dq_list.py

package info (click to toggle)
yt 4.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,084 kB
  • sloc: python: 132,484; ansic: 5,628; cpp: 1,588; javascript: 352; makefile: 138; sh: 43; csh: 36
file content (40 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download | duplicates (3)
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
import inspect
from textwrap import TextWrapper

import yt

ds = yt.load("RD0005-mine/RedshiftOutput0005")

output = open("source/analyzing/_dq_docstrings.inc", "w")

template = """

.. function:: %(funcname)s%(sig)s:

   (This is a proxy for :func:`~%(funcproxy)s`.)
%(docstring)s

"""

tw = TextWrapper(initial_indent="   ", subsequent_indent="   ", width=60)


def write_docstring(f, name, func):
    docstring = inspect.getdoc(func)
    funcname = name
    sig = inspect.formatargspec(*inspect.getargspec(func))
    sig = sig.replace("data, ", "")
    sig = sig.replace("(data)", "()")
    funcproxy = f"yt.data_objects.derived_quantities.{func.__name__}"
    docstring = "\n".join("   %s" % line for line in docstring.split("\n"))
    f.write(
        template
        % dict(funcname=funcname, sig=sig, funcproxy=funcproxy, docstring=docstring)
    )
    # docstring = "\n".join(tw.wrap(docstring))))


dd = ds.all_data()
for n, func in sorted(dd.quantities.functions.items()):
    print(n, func)
    write_docstring(output, n, func[1])