Skip to content

Commit ef862aa

Browse files
committed
👔 Handle NodeBlockFunctions as their own type of object
1 parent adb74ff commit ef862aa

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

docs/_sources/autodoc_nodeblock.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

docs/_sources/conf.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939
# https://python-semver.readthedocs.io/en/latest/usage.html
4040

4141

42-
class DocumentNodeBlockFunction(FunctionDocumenter):
43-
"""Document Node Block Functions"""
44-
objtype = 'Function'
45-
priority = 10
42+
# class DocumentNodeBlockFunction(FunctionDocumenter):
43+
# """Document Node Block Functions"""
44+
# objtype = 'Function'
45+
# priority = 10
4646

47-
@classmethod
48-
def can_document_member(cls, member: Any, membername: str, isattr: bool,
49-
parent: Any) -> bool:
50-
"""Determine if a member is a NodeBlockFunction"""
51-
return isinstance(member, NodeBlockFunction)
47+
# @classmethod
48+
# def can_document_member(cls, member: Any, membername: str, isattr: bool,
49+
# parent: Any) -> bool:
50+
# """Determine if a member is a NodeBlockFunction"""
51+
# return isinstance(member, NodeBlockFunction)
5252

5353

5454
def coerce(version):
@@ -163,6 +163,7 @@ def yaml_to_rst(path):
163163
'sphinx.ext.napoleon',
164164
'sphinx.ext.viewcode',
165165
'sphinxcontrib.programoutput',
166+
'autodoc_nodeblock',
166167
'exec',
167168
'nbsphinx']
168169

@@ -644,7 +645,7 @@ def initialize_factory() -> None:
644645
def setup(app) -> None:
645646
"""Extend Sphinx"""
646647
# Node Block Function customizations
647-
app.setup_extension('sphinx.directives')
648-
app.add_autodocumenter(DocumentNodeBlockFunction)
648+
# app.setup_extension('sphinx.directives')
649+
# app.add_autodocumenter(DocumentNodeBlockFunction)
649650
# modify docstrings before parsing RST
650651
app.connect('autodoc-process-docstring', autodoc_process_docstring)

0 commit comments

Comments
 (0)