File: parse_object_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 (41 lines) | stat: -rw-r--r-- 1,062 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
41
import inspect
from textwrap import TextWrapper

import yt

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

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

template = """

.. class:: %(clsname)s%(sig)s:

   For more information, see :ref:`%(docstring)s`
   (This is a proxy for :class:`~%(clsproxy)sBase`.)
"""

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


def write_docstring(f, name, cls):
    for clsi in inspect.getmro(cls):
        docstring = inspect.getdoc(clsi.__init__)
        if docstring is not None:
            break
    clsname = name
    sig = inspect.formatargspec(*inspect.getargspec(cls.__init__))
    sig = sig.replace("**kwargs", "**field_parameters")
    clsproxy = f"yt.data_objects.data_containers.{cls.__name__}"
    f.write(
        template
        % dict(
            clsname=clsname, sig=sig, clsproxy=clsproxy, docstring="physical-object-api"
        )
    )


for n, c in sorted(ds.__dict__.items()):
    if hasattr(c, "_con_args"):
        print(n)
        write_docstring(output, n, c)