From d6f1564744039090bda52372c1ce2318596ee1d4 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 9 Dec 2021 19:47:35 +0100 Subject: [PATCH] path for dyn option with leadership in calculation --- tiramisu/autolib.py | 4 +- tiramisu/option/syndynoptiondescription.py | 52 +++++++++++----------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index 9e4ac0c..9f49bc3 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -363,9 +363,11 @@ async def manager_callback(callbk: Param, callbk_option.impl_get_display_name(), )) #FIXME in same dynamic option? - rootpath = option.rootpath suffix = option.impl_getsuffix() + rootpath = option.rootpath subdyn = callbk_option.getsubdyn() + if len(callbk_option.impl_getpath().split('.')) == len(rootpath.split('.')): + rootpath = rootpath.rsplit('.', 1)[0] callbk_option = callbk_option.to_dynoption(rootpath, suffix, subdyn) diff --git a/tiramisu/option/syndynoptiondescription.py b/tiramisu/option/syndynoptiondescription.py index 4a4180e..2e3539e 100644 --- a/tiramisu/option/syndynoptiondescription.py +++ b/tiramisu/option/syndynoptiondescription.py @@ -29,7 +29,7 @@ from .syndynoption import SynDynOption class SynDynOptionDescription: - __slots__ = ('_opt', + __slots__ = ('opt', 'rootpath', '_suffix', 'ori_dyn') @@ -39,7 +39,7 @@ class SynDynOptionDescription: rootpath: str, suffix: str, ori_dyn) -> None: - self._opt = opt + self.opt = opt if rootpath is None: rootpath = '' assert isinstance(rootpath, str), 'rootpath must be a string, not {}'.format(type(rootpath)) @@ -50,12 +50,12 @@ class SynDynOptionDescription: def __getattr__(self, name: str) -> Any: - # if not in SynDynOptionDescription, get value in self._opt - return getattr(self._opt, + # if not in SynDynOptionDescription, get value in self.opt + return getattr(self.opt, name) def impl_getopt(self) -> BaseOption: - return self._opt + return self.opt async def get_child(self, name: str, @@ -71,13 +71,13 @@ class SynDynOptionDescription: else: return child.to_dynoption(subpath, self._suffix, - self._opt) + self.opt) raise AttributeError(_('unknown option "{0}" ' 'in dynamic optiondescription "{1}"' '').format(name, self.impl_get_display_name())) def impl_getname(self) -> str: - return self._opt.impl_getname() + self._suffix + return self.opt.impl_getname() + self._suffix def impl_is_dynoptiondescription(self) -> bool: return True @@ -88,10 +88,10 @@ class SynDynOptionDescription: ): subpath = self.impl_getpath() children = [] - for child in await self._opt.get_children(config_bag): + for child in await self.opt.get_children(config_bag): children.append(child.to_dynoption(subpath, self._suffix, - self._opt)) + self.opt)) return children def impl_is_dynsymlinkoption(self) -> bool: @@ -102,10 +102,10 @@ class SynDynOptionDescription: byname: Optional[str], config_bag: ConfigBag, self_opt: BaseOption=None) -> BaseOption: - async for option in self._opt.get_children_recursively(bytype, - byname, - config_bag, - self): + async for option in self.opt.get_children_recursively(bytype, + byname, + config_bag, + self): yield option def impl_getpath(self) -> str: @@ -115,18 +115,18 @@ class SynDynOptionDescription: return rootpath + self.impl_getname() def impl_get_display_name(self) -> str: - return self._opt.impl_get_display_name() + self._suffix + return self.opt.impl_get_display_name() + self._suffix class SynDynLeadership(SynDynOptionDescription): def get_leader(self) -> SynDynOption: - return self._opt.get_leader().to_dynoption(self.impl_getpath(), - self._suffix, - self.ori_dyn) + return self.opt.get_leader().to_dynoption(self.impl_getpath(), + self._suffix, + self.ori_dyn) def get_followers(self) -> Iterator[SynDynOption]: subpath = self.impl_getpath() - for follower in self._opt.get_followers(): + for follower in self.opt.get_followers(): yield follower.to_dynoption(subpath, self._suffix, self.ori_dyn) @@ -146,20 +146,20 @@ class SynDynLeadership(SynDynOptionDescription): async def pop(self, *args, **kwargs) -> None: - await self._opt.pop(*args, - followers=self.get_followers(), - **kwargs) + await self.opt.pop(*args, + followers=self.get_followers(), + **kwargs) async def follower_force_store_value(self, values, value, option_bag, owner) -> None: - await self._opt.follower_force_store_value(values, - value, - option_bag, - owner, - dyn=self) + await self.opt.follower_force_store_value(values, + value, + option_bag, + owner, + dyn=self) def impl_getsuffix(self) -> str: return self._suffix