From c483b27ed10cb91d4c622e696e158fdae74dcd8c Mon Sep 17 00:00:00 2001 From: Samuel Felton Date: Mon, 4 Dec 2023 23:02:04 +0100 Subject: [PATCH] documentation for enums --- .../visp_python_bindgen/doc_parser.py | 20 ++++++++++++++++--- .../visp_python_bindgen/enum_binding.py | 7 +++---- .../visp_python_bindgen/submodule.py | 2 ++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/modules/python/generator/visp_python_bindgen/doc_parser.py b/modules/python/generator/visp_python_bindgen/doc_parser.py index b131d1d268..d6e060dc6e 100644 --- a/modules/python/generator/visp_python_bindgen/doc_parser.py +++ b/modules/python/generator/visp_python_bindgen/doc_parser.py @@ -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): @@ -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: diff --git a/modules/python/generator/visp_python_bindgen/enum_binding.py b/modules/python/generator/visp_python_bindgen/enum_binding.py index c353969dd9..23f417ee1e 100644 --- a/modules/python/generator/visp_python_bindgen/enum_binding.py +++ b/modules/python/generator/visp_python_bindgen/enum_binding.py @@ -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});') diff --git a/modules/python/generator/visp_python_bindgen/submodule.py b/modules/python/generator/visp_python_bindgen/submodule.py index fa4feb4cb6..3e1f811aa7 100644 --- a/modules/python/generator/visp_python_bindgen/submodule.py +++ b/modules/python/generator/visp_python_bindgen/submodule.py @@ -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