Skip to content

Commit 658589d

Browse files
committed
Enhance api export
1 parent 62834a6 commit 658589d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,5 @@ dev = [
6363
"ruff>=0.9.2",
6464
"pytest>=7.2.0",
6565
"pytest-cov>=0.6",
66+
"docstring-parser>=0.16",
6667
]

tools/export_ips.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,35 @@
44
import sys
55

66
from amaranth.lib import wiring
7+
from docstring_parser import parse_from_object
78

89
import chipflow_digital_ip
910

1011
def children(mod):
11-
stack = [(attr, getattr(mod, attr)) for attr in dir(mod) if not attr.startswith("_")]
12+
level = "chipflow_digital_ip"
13+
stack = [(f"{level}.{attr}", getattr(mod, attr)) for attr in dir(mod) if not attr.startswith("_")]
1214
done = []
1315
while stack:
1416
i = stack.pop()
1517
e,o = i
1618
if inspect.isclass(o) and o.__module__.startswith('chipflow_digital_ip') and issubclass(o, wiring.Component):
17-
yield o
19+
yield e,o
1820
if inspect.ismodule(o):
1921
if e in done:
2022
continue
2123
done.append(e)
22-
stack.extend([(attr, getattr(o, attr)) for attr in dir(o) if not attr.startswith("_")])
24+
stack.extend([(f"{e}.{attr}", getattr(o, attr)) for attr in dir(o) if not attr.startswith("_")])
2325

2426
gen = children(chipflow_digital_ip)
2527
output={}
26-
for cls in gen:
27-
output[f"{cls.__module__}.{cls.__qualname__}"]=cls.__doc__
28+
for name, cls in gen:
29+
docstring = parse_from_object(cls)
30+
d = {
31+
'short_description': docstring.short_description,
32+
'long_description': docstring.long_description,
33+
'params': [p.__dict__ for p in docstring.params],
34+
'examples': [ e.__dict__ for e in docstring.examples],
35+
}
36+
output[name] = d
2837

2938
json.dump(output, sys.stdout, indent=2)

0 commit comments

Comments
 (0)