From 1a793451306bc93d4373b3a4f7b8bdb0d1855b7a Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Fri, 11 Mar 2022 15:34:31 +0000 Subject: [PATCH] PRS: Enable preview rendering on pull requests (#2023) --- build.py | 1 + pep_sphinx_extensions/__init__.py | 16 +++++++++++++++- readthedocs.yaml | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 readthedocs.yaml diff --git a/build.py b/build.py index decb84e71..d2493cafc 100755 --- a/build.py +++ b/build.py @@ -81,6 +81,7 @@ if __name__ == "__main__": confoverrides=config_overrides, warningiserror=args.fail_on_warning, parallel=args.jobs, + tags=["internal_builder"], ) app.build() diff --git a/pep_sphinx_extensions/__init__.py b/pep_sphinx_extensions/__init__.py index bbd839449..e9d366ca1 100644 --- a/pep_sphinx_extensions/__init__.py +++ b/pep_sphinx_extensions/__init__.py @@ -22,11 +22,25 @@ def _depart_maths(): pass # No-op callable for the type checker -def _update_config_for_builder(app: Sphinx): +def _update_config_for_builder(app: Sphinx) -> None: app.env.document_ids = {} # For PEPReferenceRoleTitleText if app.builder.name == "dirhtml": app.env.settings["pep_url"] = "../pep-{:0>4}" + # internal_builder exists if Sphinx is run by build.py + if "internal_builder" not in app.tags: + app.connect("build-finished", _post_build) # Post-build tasks + + +def _post_build(app: Sphinx, exception: Exception | None) -> None: + from pathlib import Path + + from build import create_index_file + + if exception is not None: + return + create_index_file(Path(app.outdir), app.builder.name) + def setup(app: Sphinx) -> dict[str, bool]: """Initialize Sphinx extension.""" diff --git a/readthedocs.yaml b/readthedocs.yaml new file mode 100644 index 000000000..b4fa40173 --- /dev/null +++ b/readthedocs.yaml @@ -0,0 +1,16 @@ +version: 2 + +build: + os: ubuntu-20.04 + tools: + python: "3.9" + +python: + install: + - requirements: requirements.txt + +sphinx: + builder: dirhtml + +search: + ignore: ['*']