mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-06-01 10:21:59 +02:00
[docs] generate extra node doc with custom extension
This commit is contained in:
parent
e022b377c4
commit
cec2c79d6a
7 changed files with 102 additions and 13 deletions
|
@ -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:
|
||||||
|
|
60
docs/source/_ext/meshroom_doc.py
Normal file
60
docs/source/_ext/meshroom_doc.py
Normal 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,
|
||||||
|
}
|
35
docs/source/_templates/autosummary/class.rst
Normal file
35
docs/source/_templates/autosummary/class.rst
Normal 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 %}
|
|
@ -2,5 +2,4 @@ Release Notes
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
||||||
.. fetch_md::
|
.. fetch_md:: CHANGES.md
|
||||||
:file: CHANGES.md
|
|
||||||
|
|
|
@ -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']
|
||||||
|
|
|
@ -11,5 +11,4 @@ Welcome to meshroom's documentation!
|
||||||
changes
|
changes
|
||||||
|
|
||||||
|
|
||||||
.. fetch_md::
|
.. fetch_md:: README.md
|
||||||
:file: README.md
|
|
||||||
|
|
|
@ -2,5 +2,4 @@ Install
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|
||||||
.. fetch_md::
|
.. fetch_md:: INSTALL.md
|
||||||
:file: INSTALL.md
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue