Skip to content

Commit

Permalink
Merge pull request #75 from braingram/traverse_for_old_docutils
Browse files Browse the repository at this point in the history
for docutils < 0.19 use traverse instead of findall
  • Loading branch information
braingram authored Jul 28, 2023
2 parents cf01335 + 6aa2a0b commit 5fddf93
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 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
24 changes: 21 additions & 3 deletions sphinx_asdf/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import posixpath
import warnings

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

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 +44,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 +123,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 +138,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 5fddf93

Please sign in to comment.