Skip to content

Commit 9ebcff4

Browse files
committed
docs: Build function docs from docstrings
Read the docstrings using ASTs instead of importing the modules; this prevents the need to install TuneD dependencies when just building the docs (e.g., in Github Pages).
1 parent 889387b commit 9ebcff4

File tree

6 files changed

+64
-98
lines changed

6 files changed

+64
-98
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ tuned-*.tar.bz2
44
*~
55
*.html
66
doc/manual/modules/performance/ref_available-tuned-plug-ins.adoc
7+
doc/manual/modules/performance/ref_built-in-functions-available-in-tuned-profiles.adoc

compile_plugin_docs.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

doc/manual/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
.PHONY: clean
22

3-
index.html: master.adoc assemblies/*.adoc meta/*.adoc modules/performance/*.adoc ../../tuned/plugins/plugin_*.py
4-
$(PYTHON) ../../compile_plugin_docs.py modules/performance/ref_available-tuned-plug-ins_intro.adoc modules/performance/ref_available-tuned-plug-ins.adoc
3+
index.html: master.adoc assemblies/*.adoc meta/*.adoc modules/performance/*.adoc ../../tuned/plugins/plugin_*.py ../../tuned/profiles/functions/function_*.py
4+
$(PYTHON) ./compile_plugin_docs.py ../../tuned/plugins plugin_ Plugin modules/performance/ref_available-tuned-plug-ins_intro.adoc modules/performance/ref_available-tuned-plug-ins.adoc
5+
$(PYTHON) ./compile_plugin_docs.py ../../tuned/profiles/functions function_ Function modules/performance/ref_built-in-functions-available-in-tuned-profiles_intro.adoc modules/performance/ref_built-in-functions-available-in-tuned-profiles.adoc
56
asciidoctor -o index.html master.adoc || asciidoc -d book -o index.html master.adoc
67

78
install: index.html
89
install -Dpm 0644 index.html $(DESTDIR)$(DOCDIR)/manual/index.html
910

1011
clean:
1112
rm -f modules/performance/ref_available-tuned-plug-ins.adoc
13+
rm -f modules/performance/ref_built-in-functions-available-in-tuned-profiles.adoc
1214
rm -f *.html

doc/manual/compile_plugin_docs.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import ast
4+
import os
5+
import inspect
6+
7+
8+
class DocLoader:
9+
def __init__(self, directory, prefix, base):
10+
self._directory = directory
11+
self._prefix = prefix
12+
self._base = base
13+
14+
def _load_doc(self, module_path):
15+
with open(module_path, "r") as file:
16+
tree = ast.parse(file.read(), filename=module_path)
17+
for node in ast.walk(tree):
18+
if isinstance(node, ast.ClassDef) and any(
19+
hasattr(base, "attr") and base.attr == self._base for base in node.bases
20+
):
21+
return inspect.cleandoc(ast.get_docstring(node))
22+
return ""
23+
24+
def load_all_docs(self):
25+
docs = {}
26+
for filename in os.listdir(self._directory):
27+
if not filename.startswith(self._prefix):
28+
continue
29+
name = filename.split(".")[0].split("_", 1)[1]
30+
path = os.path.join(self._directory, filename)
31+
docs[name] = self._load_doc(path)
32+
return docs
33+
34+
35+
if __name__ == "__main__":
36+
parser = argparse.ArgumentParser()
37+
parser.add_argument("directory")
38+
parser.add_argument("prefix")
39+
parser.add_argument("base")
40+
parser.add_argument("intro")
41+
parser.add_argument("out")
42+
args = parser.parse_args()
43+
44+
with open(args.intro, "r") as intro_file:
45+
intro = intro_file.read()
46+
47+
doc_loader = DocLoader(args.directory, args.prefix, args.base)
48+
class_docs = doc_loader.load_all_docs()
49+
50+
with open(args.out, "w") as out_file:
51+
out_file.write(intro)
52+
for name, docs in class_docs.items():
53+
out_file.writelines(["\n", "== **%s**\n" % name, "%s\n" % docs])

doc/manual/modules/performance/ref_built-in-functions-available-in-tuned-profiles.adoc

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:_module-type: REFERENCE
2+
[id="built-in-functions-available-in-tuned-profiles_{context}"]
3+
= Built-in functions available in TuneD profiles
4+
5+
[role="_abstract"]
6+
The following built-in functions are available in all *TuneD* profiles:

0 commit comments

Comments
 (0)