- Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathbuild.py
executable file
·76 lines (61 loc) · 2.7 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# This file is placed in the public domain or under the
# CC0-1.0-Universal license, whichever is more permissive.
"""Build script for Sphinx documentation"""
importargparse
importos
frompathlibimportPath
fromsphinx.applicationimportSphinx
defcreate_parser():
parser=argparse.ArgumentParser(description="Build PEP documents")
# alternative builders:
builders=parser.add_mutually_exclusive_group()
builders.add_argument("-l", "--check-links", action="store_const",
dest="builder", const="linkcheck",
help='Check validity of links within PEP sources. '
'Cannot be used with "-f" or "-d".')
builders.add_argument("-f", "--build-files", action="store_const",
dest="builder", const="html",
help='Render PEPs to "pep-NNNN.html" files (default). '
'Cannot be used with "-d" or "-l".')
builders.add_argument("-d", "--build-dirs", action="store_const",
dest="builder", const="dirhtml",
help='Render PEPs to "index.html" files within "pep-NNNN" directories. '
'Cannot be used with "-f" or "-l".')
parser.add_argument(
"-o",
"--output-dir",
default="build",
help="Output directory, relative to root. Default 'build'.",
)
returnparser.parse_args()
defcreate_index_file(html_root: Path, builder: str) ->None:
"""Copies PEP 0 to the root index.html so that /peps/ works."""
pep_zero_file="pep-0000.html"ifbuilder=="html"else"pep-0000/index.html"
try:
pep_zero_text=html_root.joinpath(pep_zero_file).read_text(encoding="utf-8")
exceptFileNotFoundError:
returnNone
ifbuilder=="dirhtml":
pep_zero_text=pep_zero_text.replace('="../', '="') # remove relative directory links
html_root.joinpath("index.html").write_text(pep_zero_text, encoding="utf-8")
if__name__=="__main__":
args=create_parser()
root_directory=Path(__file__).resolve().parent
source_directory=root_directory/"peps"
build_directory=root_directory/args.output_dir
# builder configuration
sphinx_builder=args.builderor"html"
app=Sphinx(
source_directory,
confdir=source_directory,
outdir=build_directory/sphinx_builder,
doctreedir=build_directory/"doctrees",
buildername=sphinx_builder,
warningiserror=True,
parallel=os.cpu_count() or1,
tags=["internal_builder"],
keep_going=True,
)
app.build()
create_index_file(build_directory, sphinx_builder)