ICON Community Interface 0.4.0
Loading...
Searching...
No Matches
generate_python_api_doc.py
Go to the documentation of this file.
1# This Python plugin generates a rudimentary markdown documentation of
2# the available ComIn Python API.
3#
4# @authors 11/2023 :: ICON Community Interface <comin@icon-model.org>
5#
6# SPDX-License-Identifier: BSD-3-Clause
7#
8# Please see the file LICENSE in the root of the source tree for this code.
9# Where software is supplied by third parties, it is indicated in the
10# headers of the routines.
11
12import comin
13import inspect
14import numpy as np
15
16ignore = [
17 "dataclass",
18 "ep",
19 "name",
20 "register_callback",
21 "simulation_interval",
22 "plugin_info",
23]
24
25
26def describe(obj, f, prefix=""):
27 for element_name in dir(obj):
28 if element_name not in ignore:
29 element = getattr(obj, element_name)
30 if element_name.startswith("_"):
31 pass
32 elif element.__class__ is comin._EntryPoint:
33 print(f"- EntryPoint `{prefix}{element_name}`", file=f)
34 elif inspect.isclass(element):
35 print(f"- class {prefix}{element_name}", file=f)
36 elif inspect.ismodule(element):
37 print(f"- module {prefix}{element_name}", file=f)
38 pass
39 elif callable(element):
40 # if not inspect.isbuiltin(element):
41 print(f"- callable `{prefix}{element_name}`: {element.__doc__}", file=f)
42 pass
43 else:
44 try:
45 dims = [":"] * element.ndim
46 print(
47 f"- `{prefix}{element_name}({','.join(dims)})` ({np.asarray(element).dtype})",
48 file=f,
49 )
50 except Exception:
51 print(
52 f"- `{prefix}{element_name}` ({type(element).__name__})", file=f
53 )
54
55
56with open("comin_python_api.md", "w") as f:
57 print("# ComIn Python API", file=f)
58 print("\n\n## Global ComIn functions, variables and constants", file=f)
59 describe(comin, f)
60 print("\n\n## Members of data type plugin_info", file=f)
62 describe(plugin_info, f, prefix="plugin_info.")
63 print("\n\n## Global descriptive data", file=f)
65 describe(glob, f, prefix="global.")
66 print("\n\n## Members of data type simulation_interval", file=f)
68 describe(simulation_interval, f, prefix="simulation_interval.")
69 print("\n\n## Descriptive data for domains", file=f)
71 describe(domain, f, prefix="domain.")
72 print("\n\n## Members of data type domain.cells", file=f)
73 describe(domain.cells, f, prefix="domain.cells.")
74 print("\n\n## Members of data type domain.edges", file=f)
75 describe(domain.edges, f, prefix="domain.edges.")
76 print("\n\n## Members of data type domain.verts", file=f)
77 describe(domain.verts, f, prefix="domain.verts.")
descrdata_get_simulation_interval()
returns simulation intervals: exp_start, exp_stop, run_start, run_stop
Definition comin.py:224
current_get_plugin_info()
returns object describing the current plugin
Definition comin.py:146
descrdata_get_domain(jg)
returns descriptive data for a given domain, arguments: jg
Definition comin.py:167
descrdata_get_global()
returns global descriptive data object
Definition comin.py:172