diff --git a/generate_rss.py b/generate_rss.py index efeeb3c4d..b67c9b528 100755 --- a/generate_rss.py +++ b/generate_rss.py @@ -6,6 +6,7 @@ import datetime import email.utils from pathlib import Path +import docutils from docutils import frontend from docutils import nodes from docutils import utils @@ -19,6 +20,14 @@ def _format_rfc_2822(dt: datetime.datetime) -> str: return email.utils.format_datetime(dt, usegmt=True) +# Monkeypatch nodes.Node.findall for forwards compatability +if docutils.__version_info__ < (0, 18): + def findall(self, *args, **kwargs): + return iter(self.traverse(*args, **kwargs)) + + nodes.Node.findall = findall + + entry.formatRFC2822 = feed.formatRFC2822 = _format_rfc_2822 line_cache: dict[Path, dict[str, str]] = {} @@ -62,8 +71,7 @@ def parse_rst(text: str) -> nodes.document: def pep_abstract(full_path: Path) -> str: """Return the first paragraph of the PEP abstract""" text = full_path.read_text(encoding="utf-8") - # TODO replace .traverse with .findall when Sphinx updates to docutils>=0.18.1 - for node in parse_rst(text).traverse(nodes.section): + for node in parse_rst(text).findall(nodes.section): if node.next_node(nodes.title).astext() == "Abstract": return node.next_node(nodes.paragraph).astext().strip().replace("\n", " ") return "" diff --git a/pep_sphinx_extensions/pep_processor/html/pep_html_builder.py b/pep_sphinx_extensions/pep_processor/html/pep_html_builder.py index 5af7a49b8..4ab8b84ae 100644 --- a/pep_sphinx_extensions/pep_processor/html/pep_html_builder.py +++ b/pep_sphinx_extensions/pep_processor/html/pep_html_builder.py @@ -38,7 +38,7 @@ class FileBuilder(StandaloneHTMLBuilder): toc_tree = self.env.tocs[docname].deepcopy() if len(toc_tree[0]) > 1: toc_tree = toc_tree[0][1] # don't include document title - for node in toc_tree.traverse(nodes.reference): + for node in toc_tree.findall(nodes.reference): node["refuri"] = node["anchorname"] or '#' # fix targets toc = self.render_partial(toc_tree)["fragment"] else: