2021-06-08 19:11:26 -04:00
|
|
|
"""Build script for Sphinx documentation"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from sphinx.application import Sphinx
|
|
|
|
|
|
|
|
|
|
|
|
def create_parser():
|
|
|
|
parser = argparse.ArgumentParser(description="Build PEP documents")
|
|
|
|
# alternative builders:
|
|
|
|
parser.add_argument("-l", "--check-links", action="store_true")
|
2021-06-09 09:02:16 -04:00
|
|
|
parser.add_argument("-f", "--build-files", action="store_true")
|
|
|
|
parser.add_argument("-d", "--build-dirs", action="store_true")
|
2021-06-08 19:11:26 -04:00
|
|
|
|
|
|
|
# flags / options
|
2021-06-09 09:02:16 -04:00
|
|
|
parser.add_argument("-w", "--fail-on-warning", action="store_true")
|
2021-06-08 19:11:26 -04:00
|
|
|
parser.add_argument("-n", "--nitpicky", action="store_true")
|
2021-06-08 20:37:55 -04:00
|
|
|
parser.add_argument("-j", "--jobs", type=int, default=1)
|
2021-06-08 19:11:26 -04:00
|
|
|
|
|
|
|
# extra build steps
|
|
|
|
parser.add_argument("-i", "--index-file", action="store_true") # for PEP 0
|
|
|
|
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
args = create_parser()
|
|
|
|
|
|
|
|
root_directory = Path(".").absolute()
|
|
|
|
source_directory = root_directory
|
|
|
|
build_directory = root_directory / "build" # synchronise with deploy-gh-pages.yaml -> deploy step
|
|
|
|
doctree_directory = build_directory / ".doctrees"
|
|
|
|
|
|
|
|
# builder configuration
|
2021-06-09 09:02:16 -04:00
|
|
|
if args.build_files:
|
|
|
|
sphinx_builder = "html"
|
|
|
|
elif args.build_dirs:
|
|
|
|
sphinx_builder = "dirhtml"
|
|
|
|
elif args.check_links:
|
2021-06-08 19:11:26 -04:00
|
|
|
sphinx_builder = "linkcheck"
|
2021-06-09 09:02:16 -04:00
|
|
|
else:
|
|
|
|
# default builder
|
|
|
|
sphinx_builder = "dirhtml"
|
2021-06-08 19:11:26 -04:00
|
|
|
|
|
|
|
# other configuration
|
|
|
|
config_overrides = {}
|
|
|
|
if args.nitpicky:
|
|
|
|
config_overrides["nitpicky"] = True
|
|
|
|
|
|
|
|
app = Sphinx(
|
|
|
|
source_directory,
|
|
|
|
confdir=source_directory,
|
|
|
|
outdir=build_directory,
|
|
|
|
doctreedir=doctree_directory,
|
|
|
|
buildername=sphinx_builder,
|
|
|
|
confoverrides=config_overrides,
|
|
|
|
warningiserror=args.fail_on_warning,
|
|
|
|
parallel=args.jobs,
|
|
|
|
)
|
|
|
|
app.builder.copysource = False # Prevent unneeded source copying - we link direct to GitHub
|
|
|
|
app.build()
|