Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c113b0296ab8fbfdddacf3864b09a42d3fb718ea
[simgrid.git] / docs / source / _ext / autodoxy / __init__.py
1 import os.path
2 from lxml import etree as ET
3 from sphinx.errors import ExtensionError
4
5 import sphinx.ext.autosummary
6 from autodoxy import DoxygenClassDocumenter, DoxygenMethodDocumenter, DoxygenTypeDocumenter
7 from autodoxy.autosummary import DoxygenAutosummary, DoxygenAutoEnum
8 from autodoxy.autosummary.generate import process_generate_options
9
10 def set_doxygen_xml(app):
11     """Load all doxygen XML files from the app config variable
12     `app.config.doxygen_xml` which should be a path to a directory
13     containing doxygen xml output
14     """
15     err = ExtensionError(
16         '[autodoxy] No doxygen xml output found in doxygen_xml="%s"' % app.config.doxygen_xml)
17
18     if not os.path.isdir(app.config.doxygen_xml):
19         raise err
20
21     files = [os.path.join(app.config.doxygen_xml, f)
22              for f in os.listdir(app.config.doxygen_xml)
23              if f.lower().endswith('.xml') and not f.startswith('._')]
24     if len(files) == 0:
25         raise err
26
27     setup.DOXYGEN_ROOT = ET.ElementTree(ET.Element('root')).getroot()
28     for file in files:
29         root = ET.parse(file).getroot()
30         for node in root:
31             setup.DOXYGEN_ROOT.append(node)
32
33 def get_doxygen_root():
34     """Get the root element of the doxygen XML document.
35     """
36     if not hasattr(setup, 'DOXYGEN_ROOT'):
37         setup.DOXYGEN_ROOT = ET.Element("root")  # dummy
38     return setup.DOXYGEN_ROOT
39
40 def setup(app):
41
42     app.connect("builder-inited", set_doxygen_xml)
43     app.connect("builder-inited", process_generate_options)
44
45     app.setup_extension('sphinx.ext.autodoc')
46     app.setup_extension('sphinx.ext.autosummary')
47
48     app.add_autodocumenter(DoxygenClassDocumenter)
49     app.add_autodocumenter(DoxygenMethodDocumenter)
50     app.add_autodocumenter(DoxygenTypeDocumenter)
51     app.add_config_value("doxygen_xml", "", 'env')
52     app.add_config_value('autosummary_toctree', '', 'html')
53
54     app.add_directive('autodoxysummary', DoxygenAutosummary)
55     app.add_directive('autodoxyenum', DoxygenAutoEnum)
56
57     return {'version': sphinx.__display_version__, 'parallel_read_safe': True}