-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild_doc.py
26 lines (19 loc) · 956 Bytes
/
build_doc.py
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
# Extracts the documentation from horned owl to attach it to the python types
import json
import os
import subprocess
# path to local horned owl copy
HORNED_OWL_PATH = "../horned-owl"
subprocess.call("cargo rustdoc -Z unstable-options --output-format json".split(" "), cwd=HORNED_OWL_PATH)
with open(os.path.join(HORNED_OWL_PATH, "target", "doc", "horned_owl.json")) as f:
data = json.load(f)
docs = dict([(x['name'], x['docs']) for x in data["index"].values() if
x['span'] is not None and x['span']['filename'] == "src/model.rs" and
x['name'] is not None and
x['docs'] is not None and
('struct' in x['inner'] or 'enum' in x['inner'] or 'variant' in x['inner'])])
lines = [f' ({n}) => {{ {json.dumps(d)} }};' for n, d in docs.items()]
lines.sort()
lines.append(" ($t:ident) => {\"\"}")
with open("src/doc.rs", "w") as f:
f.write('macro_rules! doc (\n' + "\n".join(lines) + '\n);\n')