Skip to content

Commit

Permalink
for docutils < 0.19 use traverse instead of findall
Browse files Browse the repository at this point in the history
see the code comment for some details but somehow
the docs build without errors or warnings but the side
menu for sphinx-rtd-theme fails to scroll
  • Loading branch information
braingram committed Jul 27, 2023
1 parent cf01335 commit eab90d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ install_requires =
astropy>=5.0.4
docutils
mistune>=3
packaging
sphinx
sphinx-astropy
sphinx_bootstrap_theme
Expand Down
23 changes: 19 additions & 4 deletions sphinx_asdf/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import posixpath
import warnings

import sphinx.builders
import docutils
from docutils import nodes
import packaging.version
import sphinx.builders
from sphinx.util import rst
from sphinx.util.docutils import sphinx_domains
from sphinx.util.fileutil import copy_asset
Expand All @@ -14,6 +16,19 @@

TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), "templates")

# docutils 0.19.0 fixed a bug in traverse/findall
# https://sourceforge.net/p/docutils/bugs/448/
# however sphinx-rtd-theme currently pins docutils to <0.19
# docutils has since deprecated traverse so for packages that don't
# use sphinx-rtd-theme (and will fetch 0.19.0) using findall will
# avoid the deprecation warnings
if packaging.version.parse(docutils.__version__) >= packaging.version.parse('0.19.0'):
def traverse(doctree, *args, **kwargs):
return doctree.findall(*args, **kwargs)
else:
def traverse(doctree, *args, **kwargs):
return doctree.traverse(*args, **kwargs)


def find_autoasdf_directives(env, filename):
if filename.endswith(".md"):
Expand All @@ -26,7 +41,7 @@ def find_autoasdf_directives(env, filename):
builder.read_doc(docname)
doctree = env.get_and_resolve_doctree(docname, builder)

return doctree.findall(schema_def)
return traverse(doctree, schema_def)


def find_autoschema_references(app, genfiles):
Expand Down Expand Up @@ -105,7 +120,7 @@ def update_app_config(app, config):
def handle_page_context(app, pagename, templatename, ctx, doctree):
# Use custom template when rendering pages containing schema documentation.
# This allows us to selectively include bootstrap
if doctree is not None and doctree.findall(schema_doc):
if doctree is not None and traverse(doctree, schema_doc):
return os.path.join(TEMPLATE_PATH, "schema.html")


Expand All @@ -120,7 +135,7 @@ def add_labels_to_nodes(app, document):
anonlabels = app.env.domaindata["std"]["anonlabels"]
basepath = os.path.join("generated", app.env.config.asdf_schema_standard_prefix)

for node in document.findall():
for node in traverse(document):
if isinstance(node, str) or not (isinstance(node, nodes.Node) and node["ids"]):
continue

Expand Down

0 comments on commit eab90d1

Please sign in to comment.