Skip to content

Commit 8504757

Browse files
committed
For init pages: only create links if docstrings exist.
1 parent 615667f commit 8504757

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

docs/gen_ref_pages.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,32 @@ def get_init_entries(module_instance, init_entries, prefix=""):
3030
return init_entries
3131

3232

33-
def set_init_pages(module_instance, nav):
33+
def get_init_doc_contents(module_name, members, collection):
34+
output = ""
35+
for name, target_path in members:
36+
if collection[target_path].has_docstring:
37+
output += f"- [{name}][{target_path}]\n"
38+
else:
39+
output += f"- {name}\n"
40+
if len(output) > 0:
41+
example_name, _ = members[0]
42+
prepend = (
43+
f"The following can be imported like this (using ```{example_name}``` as an example):\n\n"
44+
f"```from {TOP_LEVEL_NAME}.{module_name} import {example_name}```\n\n"
45+
"## Module members"
46+
)
47+
output = f"{prepend}\n\n{output}"
48+
return output
49+
50+
51+
def set_init_pages(module_instance, collection, nav):
3452
init_entries = get_init_entries(module_instance, {}, prefix="")
3553
for k, v in init_entries.items():
3654
k_split = k.split(".")
3755
doc_path = Path(*k_split, "index").with_suffix(".md")
3856
full_doc_path = Path(FOLDER, doc_path)
3957
nav[k_split] = doc_path
40-
to_write = "\n".join([f"- [{x[0]}][{x[1]}]" for x in v])
58+
to_write = get_init_doc_contents(k, v, collection)
4159
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
4260
fd.write(to_write)
4361

@@ -70,7 +88,7 @@ def main():
7088
loader = GriffeLoader(modules_collection=collection)
7189
module_instance = loader.load_module(Path("src", TOP_LEVEL_NAME))
7290
nav = mkdocs_gen_files.Nav()
73-
set_init_pages(module_instance, nav)
91+
set_init_pages(module_instance, collection, nav)
7492
set_non_init_pages(collection, nav)
7593
with mkdocs_gen_files.open(f"{FOLDER}/SUMMARY.md", "w") as nav_file:
7694
nav_file.writelines(nav.build_literate_nav())

0 commit comments

Comments
 (0)