77from pathlib import Path
88from shutil import copy , move , rmtree
99from subprocess import Popen # nosec
10- from typing import Dict , List
1110
1211__all__ = ("generate_documentation" ,)
1312
@@ -38,39 +37,11 @@ def _parse_package(source: Path):
3837 yield (namespace .module , namespace .names )
3938
4039
41- def _generate_reference (source : Path , destination : Path , ext : str ):
42- """Generate reference."""
43- nav_items : Dict [str , List [str ]] = {"API" : []}
44- # generate reference content
45- for module_name , aliases in _parse_package (source ):
46- for alias in aliases :
47- _write_ref_content (destination / f"{ module_name } .{ ext } " , module_name , alias .name )
48- if ext == "md" :
49- nav_items ["API" ].append (f"references/{ module_name } .md" )
50- return nav_items
51-
52-
53- def _update_mkdocs_config (source : Path , destination : Path , nav_items : Dict [str , List [str ]]):
54- """Temporary update to mkdocs config."""
55- # external
56- from yaml import safe_dump , safe_load
57-
58- copy (source , destination )
59- with open (source , "rt" ) as mkf :
60- mkdocs_conf = safe_load (mkf )
61- mkdocs_conf ["nav" ] += [nav_items ]
62- with open (source , "wt" ) as mkf :
63- safe_dump (mkdocs_conf , mkf , sort_keys = False )
64-
65-
6640def _gen_md_docs (source : Path , refs_path : Path ):
6741 """Generate Markdown docs."""
6842 # remove existing markdown files
6943 for md_files in (source / "docs/references" ).glob ("*.md" ):
7044 md_files .unlink ()
71- nav_items = _generate_reference (source / "src/validators/__init__.py" , refs_path , "md" )
72- # backup mkdocs config
73- _update_mkdocs_config (source / "mkdocs.yaml" , source / "mkdocs.bak.yaml" , nav_items )
7445 # build mkdocs as subprocess
7546 mkdocs_build = Popen (("mkdocs" , "build" )) # nosec
7647 mkdocs_build .communicate ()
@@ -97,7 +68,9 @@ def _gen_rst_docs(source: Path, refs_path: Path, only_web: bool = False, only_ma
9768 + "\n references/*\n "
9869 )
9970 # generate RST reference documentation
100- _generate_reference (source / "src/validators/__init__.py" , refs_path , "rst" )
71+ for module_name , aliases in _parse_package (source / "src/validators/__init__.py" ):
72+ for alias in aliases :
73+ _write_ref_content (refs_path / f"{ module_name } .rst" , module_name , alias .name )
10174 exit_code = 0
10275 if not only_man :
10376 # build sphinx web pages as subprocess
0 commit comments