From aa79d9a7106043af2a49f35985e1ccf9ca892ea1 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 28 Jun 2023 22:26:01 +0200 Subject: [PATCH] deletion of the cache when changinf information for an option if needed --- tests/test_option_callback.py | 4 +-- tiramisu/autolib.py | 8 +++--- tiramisu/config.py | 12 ++++----- tiramisu/option/baseoption.py | 10 ++------ tiramisu/option/option.py | 38 +++++++++++++--------------- tiramisu/option/optiondescription.py | 5 ++-- tiramisu/value.py | 10 ++++++-- 7 files changed, 41 insertions(+), 46 deletions(-) diff --git a/tests/test_option_callback.py b/tests/test_option_callback.py index 31189e7..96003a6 100644 --- a/tests/test_option_callback.py +++ b/tests/test_option_callback.py @@ -423,8 +423,8 @@ def test_callback_information3(config_type): cfg.property.read_write() cfg = get_config(cfg, config_type) assert cfg.option('val2').value.get() == 'new_value' - #FIXME cache: cfg.option('val1').information.set('information', 'new_value2') - #assert cfg.option('val2').value.get() == 'new_value2' + cfg.option('val1').information.set('information', 'new_value2') + assert cfg.option('val2').value.get() == 'new_value2' def test_callback_value_tuple(config_type): diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index 5ce96da..e894393 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -391,10 +391,10 @@ def manager_callback(callback: Callable, else: option_bag = None try: - return config_bag.context.impl_get_information(option_bag, - param.information_name, - param.default_value, - ) + return config_bag.context.get_values().get_information(option_bag, + param.information_name, + param.default_value, + ) except ValueError as err: raise ConfigError(_('option "{}" cannot be calculated: {}').format(option.impl_get_display_name(), str(err), diff --git a/tiramisu/config.py b/tiramisu/config.py index 1e631b1..7dd1082 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -591,11 +591,10 @@ class _CommonConfig(_SubConfig): :param value: information's value (ex: "the help string") """ self._impl_values.set_information(None, # pylint: disable=no-member - key, - value, - ) - cache = self.get_description()._cache_dependencies_information.get(key, []) # pylint: disable=protected-access - for option in cache: + key, + value, + ) + for option in self.get_description()._cache_dependencies_information.get(key, []): # pylint: disable=protected-access option_bag = OptionBag(option, None, config_bag, @@ -604,7 +603,6 @@ class _CommonConfig(_SubConfig): self.reset_cache(option_bag) def impl_get_information(self, - option_bag, key, default, ): @@ -612,7 +610,7 @@ class _CommonConfig(_SubConfig): :param key: the item string (ex: "help") """ - return self._impl_values.get_information(option_bag, # pylint: disable=no-member + return self._impl_values.get_information(None, # pylint: disable=no-member key, default, ) diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index d7803cc..0157d32 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -329,13 +329,7 @@ class BaseOption(Base): """ return False - def get_dependencies_information(self, - itself=False, - ) -> List[str]: + def get_dependencies_information(self) -> List[str]: """get dependencies information """ - if itself: - idx = 1 - else: - idx = 0 - return getattr(self, '_dependencies_information', [[], []])[idx] + return getattr(self, '_dependencies_information', {}) diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 5369b68..f97847f 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -65,7 +65,6 @@ class Option(BaseOption): warnings_only: bool=False, extra: Optional[Dict]=None): _setattr = object.__setattr__ - _dependencies_information = [[], []] if not multi and default_multi is not None: raise ValueError(_("default_multi is set whereas multi is False" " in option: {0}").format(name)) @@ -101,15 +100,7 @@ class Option(BaseOption): for validator in validators: if __debug__ and not isinstance(validator, Calculation): raise ValueError(_('validators must be a Calculation for "{}"').format(name)) - for param in chain(validator.params.args, validator.params.kwargs.values()): - if isinstance(param, ParamOption): - param.option._add_dependency(self) - self._has_dependency = True - elif isinstance(param, ParamSelfInformation): - _dependencies_information[1].append(param.information_name) - elif isinstance(param, ParamInformation): - _dependencies_information[0].append(param.information_name) - + self.value_dependency(validator) self._validators = tuple(validators) if extra is not None and extra != {}: _setattr(self, '_extra', extra) @@ -166,33 +157,29 @@ class Option(BaseOption): check_error=False, loaded=True, ) - self.value_dependencies(default, _dependencies_information) + self.value_dependencies(default) if (is_multi and default != []) or \ (not is_multi and default is not None): if is_multi and isinstance(default, list): default = tuple(default) _setattr(self, '_default', default) - if _dependencies_information[0] or _dependencies_information[1]: - self._dependencies_information = _dependencies_information def value_dependencies(self, value: Any, - _dependencies_information: List[str], ) -> Any: """parse dependancies to add dependencies """ if isinstance(value, list): for val in value: if isinstance(value, list): - self.value_dependencies(val, _dependencies_information) + self.value_dependencies(val) elif isinstance(value, Calculation): - self.value_dependency(val, _dependencies_information) + self.value_dependency(val) elif isinstance(value, Calculation): - self.value_dependency(value, _dependencies_information) + self.value_dependency(value) def value_dependency(self, value: Any, - _dependencies_information: List[str], ) -> Any: """parse dependancy to add dependencies """ @@ -200,10 +187,19 @@ class Option(BaseOption): if isinstance(param, ParamOption): # pylint: disable=protected-access param.option._add_dependency(self) - elif isinstance(param, ParamSelfInformation): - _dependencies_information[1].append(param.information_name) + self._has_dependency = True elif isinstance(param, ParamInformation): - _dependencies_information[0].append(param.information_name) + dest = self + if isinstance(param, ParamSelfInformation): + opt = self + elif param.option: + dest = param.option + opt = self + else: + opt = None + if not getattr(dest, '_dependencies_information', {}): + dest._dependencies_information = {} + dest._dependencies_information.setdefault(param.information_name, []).append(opt) #__________________________________________________________________________ # option's information diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index 0fada17..b73a6ae 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -88,8 +88,9 @@ class CacheOptionDescription(BaseOption): display_name, ) else: - for information in option.get_dependencies_information(): - dependencies_information.setdefault(information, []).append(option) + for information, options in option.get_dependencies_information().items(): + if None in options: + dependencies_information.setdefault(information, []).append(option) if not option.impl_is_symlinkoption(): properties = option.impl_getproperties() if 'force_store_value' in properties: diff --git a/tiramisu/value.py b/tiramisu/value.py index 021c51a..d7f0c0b 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -658,8 +658,14 @@ class Values: self._informations.setdefault(path, {})[key] = value if path is None: return - if key in option_bag.option.get_dependencies_information(itself=True): - option_bag.config_bag.context.reset_cache(option_bag) + for key, options in option_bag.option.get_dependencies_information().items(): + for option in options: + cache_option_bag = OptionBag(option, + None, + option_bag.config_bag, + properties=None, + ) + cache_option_bag.config_bag.context.reset_cache(cache_option_bag) def get_information(self, option_bag,