@@ -33,14 +33,21 @@ def parse_toc_files(toc_entries: list, files: set | None = None) -> set[str]:
3333
3434
3535def validate_toc_files (toc_files : set [str ], doc_root : Path ) -> list [str ]:
36- """Check that all files referenced in the TOC exist."""
37- # Directories with auto-generated content (gitignored, created during build)
38- generated_dirs = {"api/" , "api\\ " }
36+ """Check that all files referenced in the TOC exist.
37+
38+ Auto-generated ``api/*.md`` pages are produced by
39+ ``build_scripts/gen_api_md.py`` and are gitignored, so they are skipped
40+ while the ``doc/api/`` directory has not been generated yet (e.g. during
41+ pre-commit). Once that directory exists (i.e. after a docs build), the
42+ api/ entries are validated like any other file so the TOC stays in sync
43+ with the generator output.
44+ """
45+ skip_generated_api = not (doc_root / "api" ).exists ()
46+ api_prefixes = ("api/" , "api\\ " )
3947
4048 errors = []
4149 for file_ref in toc_files :
42- # Skip files in auto-generated directories
43- if any (file_ref .startswith (d ) for d in generated_dirs ):
50+ if skip_generated_api and file_ref .startswith (api_prefixes ):
4451 continue
4552 file_path = doc_root / file_ref
4653 if not file_path .exists ():
@@ -49,17 +56,24 @@ def validate_toc_files(toc_files: set[str], doc_root: Path) -> list[str]:
4956
5057
5158def find_orphaned_files (toc_files : set [str ], doc_root : Path ) -> list [str ]:
52- """Find documentation files not referenced in the TOC."""
59+ """Find documentation files not referenced in the TOC.
60+
61+ ``doc/api/`` holds auto-generated reference pages. They are skipped while
62+ the directory does not yet exist (pre-commit, before any docs build), but
63+ once present they are checked for orphans so the TOC reflects exactly the
64+ set of files produced by ``build_scripts/gen_api_md.py``.
65+ """
5366 skip_dirs = {
5467 "_build" ,
5568 "_api" ,
56- "api" ,
5769 "css" ,
5870 ".ipynb_checkpoints" ,
5971 "__pycache__" ,
6072 "playwright_demo" ,
6173 "generate_docs" ,
6274 }
75+ if not (doc_root / "api" ).exists ():
76+ skip_dirs .add ("api" )
6377 skip_files = {
6478 "myst.yml" ,
6579 "roakey.png" ,
0 commit comments