mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-27 22:38:10 +08:00
[docs] add enumerator description to API reference
This commit is contained in:
@@ -24,8 +24,14 @@ import type_registry
|
|||||||
def load_file(name, state):
|
def load_file(name, state):
|
||||||
state.document.settings.record_dependencies.add(name)
|
state.document.settings.record_dependencies.add(name)
|
||||||
|
|
||||||
def add_indent(lines: List[str], indent=' '):
|
def add_indent(lines: List[str], indent_depth=1):
|
||||||
return [(indent + l) for l in lines]
|
return [(' ' * indent_depth + l) for l in lines]
|
||||||
|
|
||||||
|
def format_docstring(obj, indent_depth=1):
|
||||||
|
return [
|
||||||
|
*(['', *add_indent(obj.brief.split('\n'), indent_depth)] if obj.brief else []),
|
||||||
|
*(['', *add_indent(obj.doc.split('\n'), indent_depth)] if obj.doc else []),
|
||||||
|
]
|
||||||
|
|
||||||
class Documenter():
|
class Documenter():
|
||||||
pass
|
pass
|
||||||
@@ -49,8 +55,7 @@ class MethodDocumenter(Documenter):
|
|||||||
return [
|
return [
|
||||||
'',
|
'',
|
||||||
'.. py:method:: ' + method.name + '(' + in_str + ')' + out_str,
|
'.. py:method:: ' + method.name + '(' + in_str + ')' + out_str,
|
||||||
*(['', *add_indent(method.brief.split('\n'))] if method.brief else []),
|
*(format_docstring(method, indent_depth=1)),
|
||||||
*(['', *add_indent(method.doc.split('\n'))] if method.doc else []),
|
|
||||||
'',
|
'',
|
||||||
*((' :param ' + registry.get_py_val_type_name(decl_ns_path, arg.type) + ' ' + arg.name + ':' + (' ' + arg.doc if arg.doc else '')) for arg in method.input_args),
|
*((' :param ' + registry.get_py_val_type_name(decl_ns_path, arg.type) + ' ' + arg.name + ':' + (' ' + arg.doc if arg.doc else '')) for arg in method.input_args),
|
||||||
'',
|
'',
|
||||||
@@ -65,8 +70,7 @@ class AttributeDocumenter(Documenter):
|
|||||||
'',
|
'',
|
||||||
'.. py:attribute:: ' + attr.name,
|
'.. py:attribute:: ' + attr.name,
|
||||||
' :type: ' + registry.get_py_ref_type_name(decl_ns_path, attr.type),
|
' :type: ' + registry.get_py_ref_type_name(decl_ns_path, attr.type),
|
||||||
*(['', *add_indent(attr.brief.split('\n'))] if attr.brief else []),
|
*(format_docstring(attr, indent_depth=1)),
|
||||||
*(['', *add_indent(attr.doc.split('\n'))] if attr.doc else []),
|
|
||||||
''
|
''
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -86,6 +90,7 @@ class EnumDocumenter(Documenter):
|
|||||||
'',
|
'',
|
||||||
' .. py:attribute:: ' + enumerator.name,
|
' .. py:attribute:: ' + enumerator.name,
|
||||||
' :value: {} (0x{:X})'.format(enumerator.value, enumerator.value),
|
' :value: {} (0x{:X})'.format(enumerator.value, enumerator.value),
|
||||||
|
*(format_docstring(enumerator, indent_depth=2)),
|
||||||
''
|
''
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -107,6 +112,7 @@ class BitfieldDocumenter(Documenter):
|
|||||||
'',
|
'',
|
||||||
' .. py:attribute:: ' + flag.name,
|
' .. py:attribute:: ' + flag.name,
|
||||||
' :value: {} (0x{:X})'.format(1 << flag.bit, 1 << flag.bit),
|
' :value: {} (0x{:X})'.format(1 << flag.bit, 1 << flag.bit),
|
||||||
|
*(format_docstring(flag, indent_depth=2)),
|
||||||
''
|
''
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user