diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2022-01-01 19:06:24 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2022-01-02 18:35:29 +0300 |
commit | 05a898ecb4ff8e654a053a1ba5131715a4514812 (patch) | |
tree | 1b9d286602ff2a43c903f861a525c570cb702a6e /sphinx/environment | |
parent | daf57f2488dacc6f3c45edf551fafcc32c404fc9 (diff) |
Migrate to Node.findall() from Node.traverse()
Node.traverse() was marked as deprecated since docutils-0.18. Instead
of it, Node.findall() has been added as successor of traverse().
This applies a patch to docutils-0.17 or older to be available
Node.findall() and use it.
Diffstat (limited to 'sphinx/environment')
-rw-r--r-- | sphinx/environment/__init__.py | 2 | ||||
-rw-r--r-- | sphinx/environment/adapters/toctree.py | 12 | ||||
-rw-r--r-- | sphinx/environment/collectors/asset.py | 4 | ||||
-rw-r--r-- | sphinx/environment/collectors/title.py | 2 | ||||
-rw-r--r-- | sphinx/environment/collectors/toctree.py | 2 |
5 files changed, 11 insertions, 11 deletions
diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 0f7dbd8c7..9dde7b407 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -535,7 +535,7 @@ class BuildEnvironment: self.apply_post_transforms(doctree, docname) # now, resolve all toctree nodes - for toctreenode in doctree.traverse(addnodes.toctree): + for toctreenode in doctree.findall(addnodes.toctree): result = TocTree(self).resolve(docname, builder, toctreenode, prune=prune_toctrees, includehidden=includehidden) diff --git a/sphinx/environment/adapters/toctree.py b/sphinx/environment/adapters/toctree.py index 5a9e26d6d..962e73143 100644 --- a/sphinx/environment/adapters/toctree.py +++ b/sphinx/environment/adapters/toctree.py @@ -161,7 +161,7 @@ class TocTree: process_only_nodes(toc, builder.tags) if title and toc.children and len(toc.children) == 1: child = toc.children[0] - for refnode in child.traverse(nodes.reference): + for refnode in child.findall(nodes.reference): if refnode['refuri'] == ref and \ not refnode['anchorname']: refnode.children = [nodes.Text(title)] @@ -193,13 +193,13 @@ class TocTree: for toplevel in children: # nodes with length 1 don't have any children anyway if len(toplevel) > 1: - subtrees = list(toplevel.traverse(addnodes.toctree)) + subtrees = list(toplevel.findall(addnodes.toctree)) if subtrees: toplevel[1][:] = subtrees # type: ignore else: toplevel.pop(1) # resolve all sub-toctrees - for subtocnode in list(toc.traverse(addnodes.toctree)): + for subtocnode in list(toc.findall(addnodes.toctree)): if not (subtocnode.get('hidden', False) and not includehidden): i = subtocnode.parent.index(subtocnode) + 1 @@ -257,7 +257,7 @@ class TocTree: # set the target paths in the toctrees (they are not known at TOC # generation time) - for refnode in newnode.traverse(nodes.reference): + for refnode in newnode.findall(nodes.reference): if not url_re.match(refnode['refuri']): refnode['refuri'] = builder.get_relative_uri( docname, refnode['refuri']) + refnode['anchorname'] @@ -308,7 +308,7 @@ class TocTree: # renders to nothing return nodes.paragraph() process_only_nodes(toc, builder.tags) - for node in toc.traverse(nodes.reference): + for node in toc.findall(nodes.reference): node['refuri'] = node['anchorname'] or '#' return toc @@ -324,7 +324,7 @@ class TocTree: else: kwargs['maxdepth'] = int(kwargs['maxdepth']) kwargs['collapse'] = collapse - for toctreenode in doctree.traverse(addnodes.toctree): + for toctreenode in doctree.findall(addnodes.toctree): toctree = self.resolve(docname, builder, toctreenode, prune=True, **kwargs) if toctree: toctrees.append(toctree) diff --git a/sphinx/environment/collectors/asset.py b/sphinx/environment/collectors/asset.py index 44a1248cc..9530b3bd9 100644 --- a/sphinx/environment/collectors/asset.py +++ b/sphinx/environment/collectors/asset.py @@ -43,7 +43,7 @@ class ImageCollector(EnvironmentCollector): """Process and rewrite image URIs.""" docname = app.env.docname - for node in doctree.traverse(nodes.image): + for node in doctree.findall(nodes.image): # Map the mimetype to the corresponding image. The writer may # choose the best image from these candidates. The special key * is # set if there is only single candidate to be used by a writer. @@ -124,7 +124,7 @@ class DownloadFileCollector(EnvironmentCollector): def process_doc(self, app: Sphinx, doctree: nodes.document) -> None: """Process downloadable file paths. """ - for node in doctree.traverse(addnodes.download_reference): + for node in doctree.findall(addnodes.download_reference): targetname = node['reftarget'] if '://' in targetname: node['refuri'] = targetname diff --git a/sphinx/environment/collectors/title.py b/sphinx/environment/collectors/title.py index f522231c8..8c285f323 100644 --- a/sphinx/environment/collectors/title.py +++ b/sphinx/environment/collectors/title.py @@ -43,7 +43,7 @@ class TitleCollector(EnvironmentCollector): longtitlenode = nodes.title() longtitlenode += nodes.Text(doctree['title']) # look for first section title and use that as the title - for node in doctree.traverse(nodes.section): + for node in doctree.findall(nodes.section): visitor = SphinxContentsFilter(doctree) node[0].walkabout(visitor) titlenode += visitor.get_entry_text() diff --git a/sphinx/environment/collectors/toctree.py b/sphinx/environment/collectors/toctree.py index 032703365..250e16aa2 100644 --- a/sphinx/environment/collectors/toctree.py +++ b/sphinx/environment/collectors/toctree.py @@ -196,7 +196,7 @@ class TocTreeCollector(EnvironmentCollector): for docname in env.numbered_toctrees: assigned.add(docname) doctree = env.get_doctree(docname) - for toctreenode in doctree.traverse(addnodes.toctree): + for toctreenode in doctree.findall(addnodes.toctree): depth = toctreenode.get('numbered', 0) if depth: # every numbered toctree gets new numbering |