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

sphinx 6 compat #1314

Merged
merged 1 commit into from May 9, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/pydata_sphinx_theme/toctree.py
Expand Up @@ -12,6 +12,8 @@
from sphinx.application import Sphinx
from sphinx.environment.adapters.toctree import TocTree

from .utils import traverse_or_findall


def add_inline_math(node: Node) -> str:
"""Render a node with HTML tags that activate MathJax processing.
Expand Down Expand Up @@ -72,9 +74,8 @@ def generate_header_nav_html(n_links_before_dropdown: int = 5) -> str:
# Iterate through each toctree node in the root document
# Grab the toctree pages and find the relative link + title.
links_html = []
# TODO: just use "findall" once docutils min version >=0.18.1
meth = "findall" if hasattr(root, "findall") else "traverse"
for toc in getattr(root, meth)(toctree_node):
# TODO: use `root.findall(toctree_node)` once docutils min version >=0.18.1
for toc in traverse_or_findall(root, toctree_node):
for title, page in toc.attributes["entries"]:
# if the page is using "self" use the correct link
page = toc.attributes["parent"] if page == "self" else page
Expand Down Expand Up @@ -382,9 +383,8 @@ def get_local_toctree_for(
kwargs["maxdepth"] = int(kwargs["maxdepth"])
kwargs["collapse"] = collapse

# FIX: Can just use "findall" once docutils 0.18+ is required
meth = "findall" if hasattr(doctree, "findall") else "traverse"
for toctreenode in getattr(doctree, meth)(addnodes.toctree):
# TODO: use `doctree.findall(addnodes.toctree)` once docutils min version >=0.18.1
for toctreenode in traverse_or_findall(doctree, addnodes.toctree):
toctree = self.resolve(docname, builder, toctreenode, prune=True, **kwargs)
if toctree:
toctrees.append(toctree)
Expand Down
14 changes: 11 additions & 3 deletions src/pydata_sphinx_theme/translator.py
Expand Up @@ -10,6 +10,8 @@
from sphinx.ext.autosummary import autosummary_table
from sphinx.util import logging

from .utils import traverse_or_findall

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -118,16 +120,22 @@
)

# NOTE: Replacing with underscores creates the possibility for
# conflicting references. We should check for these and warn the
# conflicting references. Here we check for these and warn the
# user if any are found.
if any(document.traverse(condition=partial(find_target, sanitized_id))):
if any(
traverse_or_findall(
document, condition=partial(find_target, sanitized_id)
)
):
logger.warning(
f'Sanitized reference "{sanitized_id}" for "{target_id}" '
"conflicts with an existing reference!"
)

# Find nodes with the given ID (there should only be one)
targets = document.traverse(condition=partial(find_target, target_id))
targets = traverse_or_findall(

Check warning on line 136 in src/pydata_sphinx_theme/translator.py

View check run for this annotation

Codecov / codecov/patch

src/pydata_sphinx_theme/translator.py#L136

Added line #L136 was not covered by tests
document, condition=partial(find_target, target_id)
)
# Replace dots with underscores in the target node ID
for target in targets:
# NOTE: By itself, modifying the target `ids` here seems to be
Expand Down