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

for docutils < 0.19 use traverse instead of findall #75

Merged
merged 2 commits into from
Jul 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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