Skip to content

Commit 530f0d5

Browse files
authored
Merge pull request #85 from coretl/patch-1
ENH: Support for sphinx 5
2 parents 2462700 + 89c03fa commit 530f0d5

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ requires-python = "~=3.7"
2828
dependencies = [
2929
"click>=7.1,<9",
3030
"pyyaml",
31-
"sphinx>=3,<5",
31+
"sphinx>=4,<6",
3232
]
3333

3434
[project.urls]

sphinx_external_toc/_compat.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import sys
77
from typing import Any, Callable, Pattern, Type
88

9+
from docutils.nodes import Element
10+
911
if sys.version_info >= (3, 10):
1012
DC_SLOTS: dict = {"slots": True}
1113
else:
@@ -136,3 +138,12 @@ def _validator(inst, attr, value):
136138
member_validator(inst, attr, member)
137139

138140
return _validator
141+
142+
143+
# Docutils compatibility
144+
145+
146+
def findall(node: Element):
147+
# findall replaces traverse in docutils v0.18
148+
# note a difference is that findall is an iterator
149+
return getattr(node, "findall", node.traverse)

sphinx_external_toc/events.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sphinx.util.docutils import SphinxDirective
1515
from sphinx.util.matching import Matcher, patfilter, patmatch
1616

17+
from ._compat import findall
1718
from .api import Document, FileItem, GlobItem, SiteMap, UrlItem
1819
from .parsing import parse_toc_yaml
1920

@@ -164,7 +165,7 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None:
164165
Adapted from `sphinx/directives/other.py::TocTree`
165166
"""
166167
# check for existing toctrees and raise warning
167-
for node in doctree.traverse(toctree_node):
168+
for node in findall(doctree)(toctree_node):
168169
create_warning(
169170
app,
170171
doctree,
@@ -174,7 +175,7 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None:
174175
)
175176

176177
toc_placeholders: List[TableOfContentsNode] = list(
177-
doctree.traverse(TableOfContentsNode)
178+
findall(doctree)(TableOfContentsNode)
178179
)
179180

180181
site_map: SiteMap = app.env.external_site_map

0 commit comments

Comments
 (0)