Skip to content

Instantly share code, notes, and snippets.

@Ogaday
Created May 15, 2025 08:41
Show Gist options
  • Save Ogaday/85768bb29c49939eaee30839ddb4703d to your computer and use it in GitHub Desktop.
Save Ogaday/85768bb29c49939eaee30839ddb4703d to your computer and use it in GitHub Desktop.
"""Create all auto docstring doc files for mkdocs if using explicit mkdocs navigation."""
import os
from pathlib import Path
API_DOCS_PATH = Path("docs/api/")
def to_module(path: Path) -> str:
return ".".join(path.parts)
def mk_doc_files(package: str):
for path, dirs, files in os.walk(f"src/{package}"):
path = Path(path).relative_to("src")
for dir_ in dirs:
dir_path = API_DOCS_PATH / path.relative_to(package) / dir_
print(f"Making directory: {dir_path}")
os.makedirs(dir_path, exist_ok=True)
for file in files:
if file != "__init__.py":
api_path = (API_DOCS_PATH / path.relative_to(package) / file).with_suffix(".md")
module = to_module(path / file.rstrip(".py"))
with open(api_path, "w") as f:
print(f"creating module docs for {module} in {api_path}")
f.write(f"::: {module}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment