Skip to content

Commit 3a5085a

Browse files
Merge pull request #1164 from roboflow/fix/remove-empty-reference-pages
Remove modules without any doscrtings from docs
2 parents 8f751bd + df7999e commit 3a5085a

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

docs/scripts/gen_ref_pages.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Generate the code reference pages."""
2-
2+
import ast
33
import os
44
from pathlib import Path
5+
from typing import Union
56

67
import mkdocs_gen_files
78

@@ -10,12 +11,36 @@
1011
"inference.enterprise.parallel.celeryconfig",
1112
]
1213

14+
15+
def module_has_docstrings(path: str) -> bool:
16+
with open(path, "r", encoding="utf-8") as f:
17+
try:
18+
tree = ast.parse(f.read(), filename=path)
19+
except SyntaxError:
20+
return False # skip broken files
21+
22+
if has_docstring(tree):
23+
return True
24+
25+
for node in tree.body:
26+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
27+
if has_docstring(node):
28+
return True
29+
return False
30+
31+
32+
def has_docstring(node: Union[ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef, ast.Module]):
33+
return ast.get_docstring(node) is not None
34+
35+
1336
if not os.environ.get("SKIP_CODEGEN"):
1437
for package in ["inference", "inference_sdk", "inference_cli"]:
1538
nav = mkdocs_gen_files.Nav()
1639
src = Path(__file__).parent.parent.parent / package
1740

1841
for path in sorted(p for p in src.rglob("*.py") if "landing" not in p.parts):
42+
if not module_has_docstrings(path=path.as_posix()):
43+
continue
1944
module_path = path.relative_to(src.parent).with_suffix("")
2045
doc_path = path.relative_to(src.parent).with_suffix(".md")
2146
full_doc_path = Path("reference", doc_path)
@@ -41,3 +66,5 @@
4166
# print("GENERATING NAVIGATION")
4267
# print("\n".join(lines))
4368
nav_file.writelines(lines)
69+
70+

0 commit comments

Comments
 (0)