From de9485b74e82f2d35d3728d3710ee49ee4918638 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 11 Dec 2023 19:38:35 +0100 Subject: [PATCH] better display function support --- tiramisu/option/baseoption.py | 42 ++++++---------------- tiramisu/option/optiondescription.py | 7 ++-- tiramisu/option/syndynoption.py | 5 +-- tiramisu/option/syndynoptiondescription.py | 5 ++- 4 files changed, 16 insertions(+), 43 deletions(-) diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 04dc405..5bb3300 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -286,39 +286,19 @@ class BaseOption(Base): raise AttributeError(_(f'"{self.impl_get_display_name()}" not part of any Config')) \ from err - def _impl_get_display_name(self, - dyn_name: Base=None, - suffix: str=None, - ) -> str: - name = self.impl_get_information('doc', None) - if name is None or name == '': - if dyn_name is not None: - name = dyn_name - else: - name = self.impl_getname() - elif suffix: - name += suffix - return name - - def _get_display_name(self, - dyn_name, - suffix, - ): - if hasattr(self, '_display_name_function'): - return self._display_name_function(self, - dyn_name, - suffix, - ) - return self._impl_get_display_name(dyn_name, - suffix, - ) - - def impl_get_display_name(self) -> str: + def impl_get_display_name(self, + dynopt=None, + ) -> str: """get display name """ - return self._get_display_name(None, - None, - ) + if dynopt is None: + dynopt = self + if hasattr(self, '_display_name_function'): + return self._display_name_function(dynopt) + name = self.impl_get_information('doc', None) + if name is None or name == '': + name = dynopt.impl_getname() + return name def reset_cache(self, path: str, diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index e3617cb..6065e65 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -225,13 +225,10 @@ class OptionDescriptionWalk(CacheOptionDescription): for child in self._children[1]: # pylint: disable=no-member if not child.impl_is_dynoptiondescription(): continue - cname = child.impl_getname() - if not name.startswith(cname): - continue for suffix in child.get_suffixes(config_bag, dynoption, ): - if name != cname + child.convert_suffix_to_path(suffix): + if name != child.impl_getname(suffix): continue return child.to_dynoption(subpath, suffix, @@ -242,7 +239,7 @@ class OptionDescriptionWalk(CacheOptionDescription): 'in root optiondescription' )) raise AttributeError(_(f'unknown option "{name}" ' - f'in optiondescription "{self.impl_get_display_name()}"' + f'in optiondescription "{self_opt.impl_get_display_name()}"' )) def get_children(self, diff --git a/tiramisu/option/syndynoption.py b/tiramisu/option/syndynoption.py index 407cc76..a14ea31 100644 --- a/tiramisu/option/syndynoption.py +++ b/tiramisu/option/syndynoption.py @@ -58,10 +58,7 @@ class SynDynOption: def impl_get_display_name(self) -> str: """get option display name """ - suffix = self.dyn_parent.getsubdyn().convert_suffix_to_path(self.suffix) - return self.opt._get_display_name(dyn_name=self.impl_getname(), # pylint: disable=protected-access - suffix=suffix, - ) + return self.opt.impl_get_display_name(self) def impl_getsuffix(self) -> str: """get suffix diff --git a/tiramisu/option/syndynoptiondescription.py b/tiramisu/option/syndynoptiondescription.py index fab5841..d9f14f2 100644 --- a/tiramisu/option/syndynoptiondescription.py +++ b/tiramisu/option/syndynoptiondescription.py @@ -81,7 +81,7 @@ class SubDynOptionDescription: return True def impl_get_display_name(self) -> str: - return self.opt.impl_get_display_name() + return self.opt.impl_get_display_name(self) def impl_is_dynoptiondescription(self) -> bool: return True @@ -131,8 +131,7 @@ class SynDynOptionDescription: def impl_get_display_name(self) -> str: """get display name """ - if self.opt.impl_is_dynoptiondescription(): - return self.opt.impl_get_display_name() + str(self._suffix) + return self.opt.impl_get_display_name(self) def get_children(self, config_bag: ConfigBag,