-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintrospect.py
More file actions
37 lines (27 loc) · 955 Bytes
/
introspect.py
File metadata and controls
37 lines (27 loc) · 955 Bytes
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
from operator import add
from pathlib import Path
from itrx import Itr
from itrx import __version__ as itrx_version
method_template = """
### `{method_name}`
{method_doc}
"""
def generate_apidoc(cls: type, file: Path) -> None:
"""
Use Itr to introspect itself for methods and their docstrings and write them to a markdown file
"""
methods = (
Itr(dir(cls))
.filter(lambda m: m in ("__init__", "__iter__", "__next__") or not m.startswith("_"))
.map(lambda m: (m, getattr(Itr, m).__doc__))
)
with file.open("w") as fd:
fd.write(f"# `Itr` v{itrx_version} class documentation\n")
fd.write(Itr.__doc__ or "")
fd.write("## Public methods\n")
fd.write(methods.map(lambda m: method_template.format(method_name=m[0], method_doc=m[1])).reduce(add))
def main() -> None:
"Entry point"
generate_apidoc(Itr, Path("./doc/apidoc.md"))
if __name__ == "__main__":
main()