55from os import getenv
66from os .path import getsize
77from pathlib import Path
8- from shutil import copy , rmtree
8+ from shutil import copy
99from subprocess import Popen # nosec
1010
1111
@@ -71,10 +71,24 @@ def _gen_rst_docs(source: Path, refs_path: Path, only_web: bool = False, only_ma
7171 + "\n \n .. toctree::"
7272 + "\n :hidden:"
7373 + "\n :maxdepth: 2"
74- + "\n :caption: Reference:"
74+ + "\n :caption: Quick Start:"
75+ + "\n :glob:\n "
76+ + "\n install_and_use"
77+ + "\n \n .. toctree::"
78+ + "\n :hidden:"
79+ + "\n :maxdepth: 2"
80+ + "\n :caption: API Reference:"
7581 + "\n :glob:\n "
7682 + "\n api/*\n "
7783 )
84+
85+ with open (source / "docs/install_and_use.rst" , "wt" ) as iau_f :
86+ iau_f .write (
87+ convert_file (source_file = source / "docs/install_and_use.md" , format = "md" , to = "rst" )
88+ .replace ("\r \n " , "\n " ) # remove carriage return in windows
89+ .replace ("’" , "'" )
90+ )
91+
7892 # generate rST reference documentation
7993 for module_name , aliases in _parse_package (source / "src/validators/__init__.py" ):
8094 for alias in aliases :
@@ -85,6 +99,7 @@ def _gen_rst_docs(source: Path, refs_path: Path, only_web: bool = False, only_ma
8599 web_build = Popen (("sphinx-build" , "docs" , "docs/_build/web" ), shell = False ) # nosec
86100 web_build .communicate ()
87101 exit_code = web_build .returncode
102+ print ("Run `python -m http.server -d docs/_build/web` to preview." )
88103 if not only_web :
89104 # build sphinx man pages as subprocess
90105 man_build = Popen ( # nosec
@@ -102,7 +117,6 @@ def _generate_documentation(
102117 only_md : bool = False ,
103118 only_rst_web : bool = False ,
104119 only_rst_man : bool = False ,
105- discard_refs : bool = True ,
106120):
107121 """Generate documentation."""
108122 if only_md is only_rst_web is only_rst_man is True :
@@ -123,16 +137,12 @@ def _generate_documentation(
123137 if exit_code == 0
124138 else exit_code
125139 )
126- # optionally discard reference folder
127- if discard_refs :
128- rmtree (refs_path )
129140 return exit_code
130141
131142
132143def package (source : Path ):
133144 """Package the source code."""
134- _generate_documentation (source , only_rst_man = True , discard_refs = False )
135- # print()
145+ _generate_documentation (source , only_rst_man = True )
136146 if getenv ("CI" , "false" ) == "true" :
137147 process = Popen (("./.venv/bin/python" , "-m" , "build" ), shell = False ) # nosec
138148 else :
@@ -149,18 +159,17 @@ def package(source: Path):
149159 from sys import argv
150160
151161 if len (argv ) != 2 :
152- quit (exit_code )
162+ print ("Expected one of these augments: `pkg` `doc` `man` or `web`" )
163+ quit (1 )
153164
154165 if argv [1 ] == "pkg" :
155166 exit_code = package (project_root )
156- if argv [1 ] == "docs" :
157- exit_code = _generate_documentation (
158- project_root ,
159- only_md = True ,
160- only_rst_web = False ,
161- only_rst_man = False ,
162- discard_refs = False ,
163- )
167+ elif argv [1 ] == "doc" :
168+ exit_code = _generate_documentation (project_root , only_md = True )
169+ elif argv [1 ] == "man" :
170+ exit_code = _generate_documentation (project_root , only_rst_man = True )
171+ elif argv [1 ] == "web" :
172+ exit_code = _generate_documentation (project_root , only_rst_web = True )
164173 quit (exit_code )
165174
166175# TODO: Address all '# nosec'
0 commit comments