From 7ae91b0f4eb119996834a4b3a95cc02cd055ab99 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 17 Nov 2018 12:08:15 +0100 Subject: [PATCH] optimize option.list() with recursive attribute --- test/test_slots.py | 2 +- tiramisu/api.py | 44 ++++++++++++++++++++++---------------------- tiramisu/config.py | 4 +--- tiramisu/value.py | 3 +-- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/test/test_slots.py b/test/test_slots.py index 8e6c4f2..a8bc210 100644 --- a/test/test_slots.py +++ b/test/test_slots.py @@ -141,7 +141,7 @@ def test_slots_config(): 'a', None, ConfigBag(c._config_bag.context)) - sc = c._config_bag.context.get_subconfig('a', option_bag) + sc = c._config_bag.context.get_subconfig(option_bag) assert isinstance(sc, SubConfig) raises(AttributeError, "sc.x = 1") raises(AttributeError, "sc.cfgimpl_x = 1") diff --git a/tiramisu/api.py b/tiramisu/api.py index e13d801..718826d 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -500,8 +500,7 @@ class _TiramisuOptionValueOptionDescription: """Dict with path as key and value""" self._get_option() name = self._option_bag.option.impl_getname() - subconfig = self._subconfig.get_subconfig(name, - self._option_bag) + subconfig = self._subconfig.get_subconfig(self._option_bag) config_bag = self._option_bag.config_bag if config_bag.properties and 'warnings' in config_bag.properties: config_bag = config_bag.copy() @@ -607,8 +606,7 @@ class _TiramisuOptionDescription(_TiramisuOption): path, None, self._config_bag) - subconfig = self._subconfig.get_subconfig(oname, - option_bag) + subconfig = self._subconfig.get_subconfig(option_bag) for path in subconfig.find(byname=name, byvalue=value, bytype=type, @@ -665,8 +663,7 @@ class _TiramisuOptionDescription(_TiramisuOption): None, self._config_bag) if opt.impl_is_optiondescription(): - self._subconfig.get_subconfig(name, - option_bag) + self._subconfig.get_subconfig(option_bag) else: subconfig.getattr(name, option_bag) @@ -686,12 +683,11 @@ class _TiramisuOptionDescription(_TiramisuOption): path, None, self._config_bag) - subconfig = self._subconfig.get_subconfig(name, - option_bag) + subconfig = self._subconfig.get_subconfig(option_bag) for opt in option.get_children(self._config_bag): try: - subsubconfig = self._filter(opt, - subconfig) + self._filter(opt, + subconfig) except PropertiesOptionError: continue if opt.impl_is_optiondescription(): @@ -1006,27 +1002,30 @@ class TiramisuContextOption(TiramisuContext): return self._find(name, value, type) def _filter(self, - opt): + opt, + subconfig): if self._config_bag.properties: option_bag = OptionBag() - path = opt.impl_getpath() option_bag.set_option(opt, - path, + opt.impl_getpath(), None, self._config_bag) if opt.impl_is_optiondescription(): self._config_bag.context.cfgimpl_get_settings().validate_properties(option_bag) - else: - self._config_bag.context.getattr(path, - option_bag) + return subconfig.get_subconfig(option_bag) + subconfig.getattr(opt.impl_getname(), + option_bag) + def _walk(self, option, recursive, type_, - group_type): + group_type, + subconfig): for opt in option.get_children(self._config_bag): try: - subsubconfig = self._filter(opt) + subsubconfig = self._filter(opt, + subconfig) except PropertiesOptionError: continue if opt.impl_is_optiondescription(): @@ -1034,16 +1033,16 @@ class TiramisuContextOption(TiramisuContext): for toption in self._walk(opt, recursive, type_, - group_type): + group_type, + subsubconfig): yield toption if type_ == 'option' or (type_ == 'optiondescription' and \ group_type and opt.impl_get_group_type() != group_type): continue elif type_ == 'optiondescription': continue + name = opt.impl_getname() path = opt.impl_getpath() - subconfig, name = self._config_bag.context.cfgimpl_get_home_by_path(path, - self._config_bag) yield TiramisuOption(name, path, None, @@ -1062,7 +1061,8 @@ class TiramisuContextOption(TiramisuContext): for toption in self._walk(option, recursive, type, - group_type): + group_type, + self._config_bag.context): yield toption diff --git a/tiramisu/config.py b/tiramisu/config.py index 7555175..5670f93 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -210,8 +210,7 @@ class SubConfig(object): config_bag) if fromconsistency is not None: option_bag.fromconsistency = fromconsistency - self = self.get_subconfig(step, - option_bag) + self = self.get_subconfig(option_bag) assert isinstance(self, SubConfig), _('unknown option {}').format(path[-1]) return self, path[-1] @@ -268,7 +267,6 @@ class SubConfig(object): return subpath def get_subconfig(self, - name, option_bag): if option_bag.fromconsistency: fromconsistency = option_bag.fromconsistency.copy() diff --git a/tiramisu/value.py b/tiramisu/value.py index d1e6144..1089c87 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -538,8 +538,7 @@ class Values(object): path, None, od_config_bag) - subsubconfig = subconfig.get_subconfig(name, - option_bag) + subsubconfig = subconfig.get_subconfig(option_bag) except PropertiesOptionError as err: pass else: