Skip to content

Commit 963a4ea

Browse files
committed
support read the docs
1 parent ba09f18 commit 963a4ea

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

build.py

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def create_index_file(html_root: Path, builder: str) -> None:
8181
confoverrides=config_overrides,
8282
warningiserror=args.fail_on_warning,
8383
parallel=args.jobs,
84+
tags=["internal_builder"],
8485
)
8586
app.build()
8687

pep_sphinx_extensions/__init__.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import TYPE_CHECKING
66

77
from docutils.writers.html5_polyglot import HTMLTranslator
8+
from jinja2.environment import Template
89
from sphinx import environment
910

1011
from pep_sphinx_extensions.pep_processor.html import pep_html_builder
@@ -22,17 +23,32 @@ def _depart_maths():
2223
pass # No-op callable for the type checker
2324

2425

25-
def _update_config_for_builder(app: Sphinx):
26+
def _update_config_for_builder(app: Sphinx) -> None:
2627
app.env.document_ids = {} # For PEPReferenceRoleTitleText
2728
if app.builder.name == "dirhtml":
2829
app.env.settings["pep_url"] = "../pep-{:0>4}"
2930

31+
# internal_builder exists if Sphinx is run by build.py
32+
if "internal_builder" not in app.tags:
33+
app.connect("build-finished", _post_build) # Post-build tasks
34+
35+
36+
def _post_build(app: Sphinx, exception: Exception | None) -> None:
37+
from pathlib import Path
38+
39+
from build import create_index_file
40+
41+
if exception is not None:
42+
return
43+
create_index_file(Path(app.outdir), app.builder.name)
44+
3045

3146
def setup(app: Sphinx) -> dict[str, bool]:
3247
"""Initialize Sphinx extension."""
3348

3449
environment.default_settings["pep_url"] = "pep-{:0>4}.html"
3550
environment.default_settings["halt_level"] = 2 # Fail on Docutils warning
51+
Template.render._patched = True # don't modify rendered HTML
3652

3753
# Register plugin logic
3854
app.add_builder(pep_html_builder.FileBuilder, override=True)

readthedocs.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
3+
build:
4+
os: ubuntu-20.04
5+
tools:
6+
python: "3.9"
7+
8+
python:
9+
install:
10+
- requirements: requirements.txt
11+
12+
sphinx:
13+
builder: dirhtml
14+
15+
search:
16+
ignore: ['*']

0 commit comments

Comments
 (0)