From dc5191d8d2845121b0f6c00e83835418739603fe Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 15 Dec 2023 18:03:58 +0000 Subject: [PATCH] Moving parsing into conf.py --- docs/cudf/parse_xml.py | 54 ------------------------------------- docs/cudf/source/conf.py | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 54 deletions(-) delete mode 100644 docs/cudf/parse_xml.py diff --git a/docs/cudf/parse_xml.py b/docs/cudf/parse_xml.py deleted file mode 100644 index 060116b6fd9..00000000000 --- a/docs/cudf/parse_xml.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (c) 2023, NVIDIA CORPORATION. - -import xml.etree.ElementTree as ET -import glob - - -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"): - 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 - - # If the id is in seen_ids we've already either removed the param or - # the entire memberdef. - if id_ not in seen_ids: - # 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(): - tparamlist.remove(param) - 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, "") - - - -for fn in glob.glob("xml/*.xml"): - tree = ET.parse(fn) - clean_definitions(tree.getroot()) - tree.write(fn) diff --git a/docs/cudf/source/conf.py b/docs/cudf/source/conf.py index f954289c523..7a7b8b86315 100644 --- a/docs/cudf/source/conf.py +++ b/docs/cudf/source/conf.py @@ -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 @@ -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"