Skip to content

Commit

Permalink
documentation for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Dec 4, 2023
1 parent 4ff1376 commit c483b27
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
20 changes: 17 additions & 3 deletions modules/python/generator/visp_python_bindgen/doc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ class EnumDocumentation(object):
general_documentation: str
value_documentation: Dict[str, str]

def get_overall_doc(self) -> str:
full_doc = ''
full_doc += self.general_documentation.strip('\n')
full_doc += '\n\nValues: \n\n'
for k,v in self.value_documentation.items():
full_doc += '* '
full_doc += '**' + k + '**'
if len(v.strip('\n').strip()) > 0:
full_doc += ': ' + v.strip('\n')
full_doc += '\n\n'

return to_cstring(full_doc)

def get_value_doc(self, k: str) -> Optional[str]:
return to_cstring(self.value_documentation.get(k) or '')

@dataclass
class DocElements(object):
Expand Down Expand Up @@ -327,16 +342,15 @@ def get_documentation_for_class(self, name: str, cpp_ref_to_python: Dict[str, st

def get_documentation_for_enum(self, enum_name: str) -> Optional[EnumDocumentation]:
member_def = self.elements.enums.get(enum_name)
print(self.elements.enums)
if member_def is None:
return None
general_doc = to_cstring(self.generate_method_description_string(member_def))
general_doc = self.generate_method_description_string(member_def)
value_doc = {}
for enum_val in member_def.enumvalue:
enum_value: doxmlparser.enumvalueType = enum_val
brief = process_description(enum_value.briefdescription)
detailed = process_description(enum_value.detaileddescription)
value_doc[enum_value.name] = to_cstring(brief + '\n\n' + detailed)
value_doc[enum_value.name] = brief + '\n\n' + detailed
return EnumDocumentation(general_doc, value_doc)

def generate_class_description_string(self, compounddef: compounddefType) -> str:
Expand Down
7 changes: 3 additions & 4 deletions modules/python/generator/visp_python_bindgen/enum_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,15 @@ def get_enum_bindings(root_scope: NamespaceScope, mapping: Dict, submodule: Subm
py_ident = f'py{owner_py_ident}{py_name}'
py_args = ['py::arithmetic()']
if enum_doc is not None:
if enum_doc.general_documentation is not None:
py_args = [enum_doc.general_documentation] + py_args
py_args = [enum_doc.get_overall_doc()] + py_args

py_args_str = ','.join(py_args)
declaration = f'py::enum_<{enum_repr.name}> {py_ident}({owner_py_ident}, "{py_name}", {py_args_str});'
values = []
for enumerator in enum_repr.values:
maybe_value_doc = None
if enum_doc is not None:
maybe_value_doc = enum_doc.value_documentation.get(enumerator.name)
# if enum_doc is not None:
# maybe_value_doc = enum_doc.get_value_doc(enumerator.name)
maybe_value_doc_str = f', {maybe_value_doc}' if maybe_value_doc else ''

values.append(f'{py_ident}.value("{enumerator.name}", {enum_repr.name}::{enumerator.name}{maybe_value_doc_str});')
Expand Down
2 changes: 2 additions & 0 deletions modules/python/generator/visp_python_bindgen/submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def generate(self) -> None:
namespace py = pybind11;
void {self.generation_function_name()}(py::module_ &m) {{
py::options options;
options.disable_enum_members_docstring();
/*
* Submodule declaration
Expand Down

0 comments on commit c483b27

Please sign in to comment.