Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 676: Use docutils.nodes.Node.findall #2363

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions generate_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import email.utils
from pathlib import Path

import docutils
from docutils import frontend
from docutils import nodes
from docutils import utils
Expand All @@ -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):
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
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]] = {}

Expand Down Expand Up @@ -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 ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_doc_context(self, docname: str, body: str, _metatags: str) -> dict:
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:
Expand Down