|
| 1 | +from typing import TYPE_CHECKING, Any |
| 2 | +from CPAC.pipeline.nodeblock import NodeBlockFunction |
| 3 | +from docutils.statemachine import StringList |
| 4 | +from sphinx.ext.autodoc import Documenter, FunctionDocumenter, bool_option |
| 5 | + |
| 6 | + |
| 7 | +class NBFMixin(Documenter): |
| 8 | + def format_name(self) -> str: |
| 9 | + """Prepend "NodeBlockFunction" to the name""" |
| 10 | + return f'NodeBlockFunction: {super().format_name()}' |
| 11 | + |
| 12 | + |
| 13 | +class NodeBlockFunctionDocumenter(NBFMixin, FunctionDocumenter): |
| 14 | + """Sphinx Documenter for NodeBlockFunction""" |
| 15 | + objtype = 'NodeBlockFunction' |
| 16 | + directivetype = FunctionDocumenter.objtype |
| 17 | + priority = 10 + FunctionDocumenter.priority |
| 18 | + option_spec = dict(FunctionDocumenter.option_spec) |
| 19 | + option_spec['hex'] = bool_option |
| 20 | + |
| 21 | + @classmethod |
| 22 | + def can_document_member(cls, member: Any, membername: str, isattr: bool, |
| 23 | + parent: Any) -> bool: |
| 24 | + """Determine if a member is a NodeBlockFunction""" |
| 25 | + return isinstance(member, NodeBlockFunction) |
| 26 | + |
| 27 | + def add_content(self, |
| 28 | + more_content: StringList | None |
| 29 | + ) -> None: |
| 30 | + |
| 31 | + super().add_content(more_content) |
| 32 | + |
| 33 | + source_name = self.get_sourcename() |
| 34 | + # nbf_object: NodeBlockFunction = self.object |
| 35 | + self.add_line('', source_name) |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +def setup(app: 'Sphinx') -> dict[str, Any]: |
| 40 | + app.setup_extension('sphinx.ext.autodoc') # Require autodoc extension |
| 41 | + app.add_autodocumenter(NodeBlockFunctionDocumenter) |
| 42 | + return { |
| 43 | + 'version': '0.1', |
| 44 | + 'parallel_read_safe': True, |
| 45 | + 'parallel_write_safe': True, |
| 46 | + } |
0 commit comments