1+ from __future__ import annotations
2+
3+ import sys
14from pathlib import Path
25
36from sphinx .application import Sphinx
@@ -29,12 +32,9 @@ def generate_api_docs():
2932 "private.misc" : [PRIVATE_MISC_TITLE ],
3033 }
3134
32- for file in sorted (PACKAGE_SRC .glob ("**/*.py" )):
33- if "node_modules" in file .parts :
34- # don't look in javascript source
35- continue
36- if file .stem .startswith ("__" ):
37- # skip __init__ and __main__
35+ for file in sorted (pathlib_walk (PACKAGE_SRC , ignore_dirs = ["node_modules" ])):
36+ if not file .suffix == ".py" or file .stem .startswith ("__" ):
37+ # skip non-Python files along with __init__ and __main__
3838 continue
3939 public_vs_private = "private" if is_private_module (file ) else "public"
4040 main_vs_misc = "main" if file_starts_with_docstring (file ) else "misc"
@@ -53,6 +53,16 @@ def generate_api_docs():
5353 PRIVATE_API_REFERENCE_FILE .write_text ("\n " .join (private_content ))
5454
5555
56+ def pathlib_walk (root : Path , ignore_dirs : list [str ]):
57+ for path in root .iterdir ():
58+ if path .is_dir ():
59+ if path .name in ignore_dirs :
60+ continue
61+ yield from pathlib_walk (path , ignore_dirs )
62+ else :
63+ yield path
64+
65+
5666def is_private_module (path : Path ) -> bool :
5767 return any (p .startswith ("_" ) for p in path .parts )
5868
@@ -75,5 +85,7 @@ def file_starts_with_docstring(path: Path) -> bool:
7585
7686
7787def setup (app : Sphinx ) -> None :
88+ if sys .platform == "win32" and sys .version_info [:2 ] == (3 , 7 ):
89+ return None
7890 generate_api_docs ()
7991 return None
0 commit comments