Skip to content

Commit

Permalink
Moving parsing into conf.py
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Dec 15, 2023
1 parent a14bc83 commit dc5191d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 54 deletions.
54 changes: 0 additions & 54 deletions docs/cudf/parse_xml.py

This file was deleted.

58 changes: 58 additions & 0 deletions docs/cudf/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import glob
import os
import re
import sys
import xml.etree.ElementTree as ET

from docutils.nodes import Text
from sphinx.addnodes import pending_xref
Expand Down Expand Up @@ -67,8 +69,64 @@ class PseudoLexer(RegexLexer):
"myst_nb",
]

# Preprocess doxygen xml for compatibility with latest Breathe
def clean_definitions(root):
# Breathe can't handle SFINAE properly:
# https://github.com/breathe-doc/breathe/issues/624
seen_ids = set()
for sectiondef in root.findall(".//sectiondef"):
for memberdef in sectiondef.findall("./memberdef"):
id_ = memberdef.get("id")
for tparamlist in memberdef.findall("./templateparamlist"):
for param in tparamlist.findall("./param"):
for type_ in param.findall("./type"):
# CUDF_ENABLE_IF or std::enable_if
if "enable_if" in ET.tostring(type_).decode().lower():
if id_ not in seen_ids:
# If this is the first time we're seeing this function,
# just remove the template parameter.
seen_ids.add(id_)
tparamlist.remove(param)
else:
# Otherwise, remove the overload altogether and just
# rely on documenting one of the SFINAE overloads.
sectiondef.remove(memberdef)
break

# In addition to enable_if, check for overloads set up by
# ...*=nullptr.
for type_ in param.findall("./defval"):
if "nullptr" in ET.tostring(type_).decode():
try:
tparamlist.remove(param)
except ValueError:
# May have already been removed in above,
# so skip.
pass
break


# All of these in type declarations cause Breathe to choke.
# For friend, see https://github.com/breathe-doc/breathe/issues/916
strings_to_remove = ("__forceinline__", "CUDF_HOST_DEVICE", "decltype(auto)", "friend")
for field in (".//type", ".//definition"):
for type_ in root.findall(field):
if type_.text is not None:
for string in strings_to_remove:
type_.text = type_.text.replace(string, "")


def clean_all_xml_files(path):
for fn in glob.glob(os.path.join(path, "*.xml")):
tree = ET.parse(fn)
clean_definitions(tree.getroot())
tree.write(fn)


# Breathe Configuration
breathe_projects = {"libcudf": "../../../cpp/doxygen/xml"}
for project_path in breathe_projects.values():
clean_all_xml_files(project_path)
breathe_default_project = "libcudf"


Expand Down

0 comments on commit dc5191d

Please sign in to comment.