From 5f06b74ee553fffdc8b4e67ace889684e8667b65 Mon Sep 17 00:00:00 2001 From: AA Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 20 Apr 2021 07:41:56 +0100 Subject: [PATCH] Add/update build and run --- build.py | 14 ++++++++++++++ conf.py | 8 ++++++++ pep_sphinx_extensions/__init__.py | 13 +++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 pep_sphinx_extensions/__init__.py diff --git a/build.py b/build.py index bd615eb1493c..0947ca7a0fb1 100644 --- a/build.py +++ b/build.py @@ -2,6 +2,7 @@ import argparse from pathlib import Path +import shutil from sphinx.application import Sphinx @@ -22,6 +23,16 @@ def create_parser(): return parser.parse_args() +def create_index_file(html_content: Path): + pep_zero_html = html_content / "pep-0000.html" + pep_zero_dir = html_content / "pep-0000" / "index.html" + + if pep_zero_html.is_file(): + shutil.copy(pep_zero_html, html_content / "index.html") + elif pep_zero_dir.is_file(): + shutil.copy(pep_zero_dir, html_content / "index.html") + + if __name__ == "__main__": args = create_parser() @@ -52,3 +63,6 @@ def create_parser(): ) app.builder.copysource = False # Prevent unneeded source copying - we link direct to GitHub app.build() + + if args.index_file: + create_index_file(build_directory) diff --git a/conf.py b/conf.py index 34835c38a3b0..9b46e4a33964 100644 --- a/conf.py +++ b/conf.py @@ -1,5 +1,10 @@ """Configuration for building PEPs using Sphinx.""" +import sys +from pathlib import Path + +sys.path.append(str(Path("pep_sphinx_extensions").absolute())) + # -- Project information ----------------------------------------------------- project = "PEPs" @@ -7,6 +12,9 @@ # -- General configuration --------------------------------------------------- +# Add any Sphinx extension module names here, as strings. +extensions = ["pep_sphinx_extensions"] + # The file extensions of source files. Sphinx uses these suffixes as sources. source_suffix = { ".rst": "restructuredtext", diff --git a/pep_sphinx_extensions/__init__.py b/pep_sphinx_extensions/__init__.py new file mode 100644 index 000000000000..25516be54c42 --- /dev/null +++ b/pep_sphinx_extensions/__init__.py @@ -0,0 +1,13 @@ +"""Sphinx extensions for performant PEP processing""" + +from sphinx.application import Sphinx + +from pep_sphinx_extensions.pep_zero_generator.pep_index_generator import create_pep_zero + + +def setup(app: Sphinx) -> dict: + """Initialise Sphinx extension.""" + + app.connect("env-before-read-docs", create_pep_zero) # PEP 0 hook + + return {"parallel_read_safe": True, "parallel_write_safe": True}