7
7
from pathlib import Path
8
8
from shutil import copy , move , rmtree
9
9
from subprocess import Popen # nosec
10
- from typing import Dict , List
11
10
12
11
__all__ = ("generate_documentation" ,)
13
12
@@ -38,39 +37,11 @@ def _parse_package(source: Path):
38
37
yield (namespace .module , namespace .names )
39
38
40
39
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
-
66
40
def _gen_md_docs (source : Path , refs_path : Path ):
67
41
"""Generate Markdown docs."""
68
42
# remove existing markdown files
69
43
for md_files in (source / "docs/references" ).glob ("*.md" ):
70
44
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 )
74
45
# build mkdocs as subprocess
75
46
mkdocs_build = Popen (("mkdocs" , "build" )) # nosec
76
47
mkdocs_build .communicate ()
@@ -97,7 +68,9 @@ def _gen_rst_docs(source: Path, refs_path: Path, only_web: bool = False, only_ma
97
68
+ "\n references/*\n "
98
69
)
99
70
# 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 )
101
74
exit_code = 0
102
75
if not only_man :
103
76
# build sphinx web pages as subprocess
0 commit comments