[docs] generate extra node doc with custom extension

This commit is contained in:
Loïc Vital 2022-10-12 18:25:10 +02:00
parent e022b377c4
commit cec2c79d6a
7 changed files with 102 additions and 13 deletions

View file

@ -38,14 +38,10 @@ class Relinker(SparseNodeVisitor):
class FetchMd(Directive): class FetchMd(Directive):
required_arguments = 2 required_arguments = 1
def arg_path(self):
if self.arguments[0] == ':file:':
return self.arguments[1]
def run(self): def run(self):
path = os.path.abspath(os.getenv('PROJECT_DIR') + '/' + self.arg_path()) path = os.path.abspath(os.getenv('PROJECT_DIR')+'/'+self.arguments[0])
result = [] result = []
try: try:
with open(path) as file: with open(path) as file:

View file

@ -0,0 +1,60 @@
from docutils import nodes
from docutils.parsers.rst import Directive
from myst_parser.docutils_ import Parser
from myst_parser.mdit_to_docutils.base import make_document
import importlib
from meshroom.core import desc
class MeshroomDoc(Directive):
required_arguments = 4
def parse_args(self):
module_name = self.arguments[self.arguments.index(':module:')+1]
class_name = self.arguments[self.arguments.index(':class:')+1]
return (module_name, class_name)
def run(self):
result = []
# Import module and class
module_name, class_name = self.parse_args()
module = importlib.import_module(module_name)
node_class = getattr(module, class_name)
# Class inherits desc.Node
if issubclass(node_class, desc.Node):
node = node_class()
parser = Parser()
# Category
doc = make_document(parser_cls=Parser)
parser.parse('**Category**: {}'.format(node.category), doc)
result.extend(doc.children)
# Documentation
doc = make_document(parser_cls=Parser)
parser.parse(node.documentation, doc)
result.extend(doc.children)
# Inputs
text_inputs = '**Inputs**: \n'
for attr in node.inputs:
text_inputs += '- {} ({})\n'.format(attr._name, attr.__class__.__name__)
doc = make_document(parser_cls=Parser)
parser.parse(text_inputs, doc)
result.extend(doc.children)
# Outputs
text_outputs = '**Outputs**: \n'
for attr in node.outputs:
text_outputs += '- {} ({})\n'.format(attr._name, attr.__class__.__name__)
doc = make_document(parser_cls=Parser)
parser.parse(text_outputs, doc)
result.extend(doc.children)
return result
def setup(app):
app.add_directive("meshroom_doc", MeshroomDoc)
return {
'version': '0.1',
'parallel_read_safe': True,
'parallel_write_safe': True,
}

View file

@ -0,0 +1,35 @@
{{ fullname | escape | underline}}
.. meshroom_doc::
:module: {{ module }}
:class: {{ objname }}
.. currentmodule:: {{ module }}
.. autoclass:: {{ objname }}
{% block methods %}
.. automethod:: __init__
{% if methods %}
.. rubric:: {{ _('Methods') }}
.. autosummary::
{% for item in methods %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}
.. autosummary::
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

View file

@ -2,5 +2,4 @@ Release Notes
============= =============
.. fetch_md:: .. fetch_md:: CHANGES.md
:file: CHANGES.md

View file

@ -25,7 +25,8 @@ author = 'AliceVision Association'
extensions = [ extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.autodoc',
'sphinx.ext.autosummary', 'sphinx.ext.autosummary',
'fetch_md' 'fetch_md',
'meshroom_doc'
] ]
templates_path = ['_templates'] templates_path = ['_templates']

View file

@ -11,5 +11,4 @@ Welcome to meshroom's documentation!
changes changes
.. fetch_md:: .. fetch_md:: README.md
:file: README.md

View file

@ -2,5 +2,4 @@ Install
======= =======
.. fetch_md:: .. fetch_md:: INSTALL.md
:file: INSTALL.md