Skip to content

Commit 7c20848

Browse files
committed
Don't generate documentation for internal modules
Internal modules (and packages) start with `_`, and should be ignored when generating the documentation. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 50155e1 commit 7c20848

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/mkdocstrings_autoapi.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,30 @@
88
"""
99

1010
from pathlib import Path
11+
from typing import Tuple
1112

1213
import mkdocs_gen_files
1314

1415
SRC_PATH = "src"
1516
DST_PATH = "reference"
1617

18+
19+
def is_internal(path_parts: Tuple[str, ...]) -> bool:
20+
"""Tell if the path is internal judging by the parts.
21+
22+
Args:
23+
path_parts: Path.parts of the path to check.
24+
25+
Returns:
26+
True if the path is internal.
27+
"""
28+
29+
def with_underscore_not_init(part: str) -> bool:
30+
return part.startswith("_") and part != "__init__"
31+
32+
return any(p for p in path_parts if with_underscore_not_init(p))
33+
34+
1735
# type ignore because mkdocs_gen_files uses a very weird module-level
1836
# __getattr__() which messes up the type system
1937
nav = mkdocs_gen_files.Nav()
@@ -24,6 +42,8 @@
2442
doc_path = path.relative_to(SRC_PATH).with_suffix(".md")
2543
full_doc_path = Path(DST_PATH, doc_path)
2644
parts = tuple(module_path.parts)
45+
if is_internal(parts):
46+
continue
2747
if parts[-1] == "__init__":
2848
doc_path = doc_path.with_name("index.md")
2949
full_doc_path = full_doc_path.with_name("index.md")

0 commit comments

Comments
 (0)