deletion of the cache when changinf information for an option if needed

This commit is contained in:
egarette@silique.fr 2023-06-28 22:26:01 +02:00
parent 3e6b90bd9c
commit aa79d9a710
7 changed files with 41 additions and 46 deletions

View file

@ -423,8 +423,8 @@ def test_callback_information3(config_type):
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
assert cfg.option('val2').value.get() == 'new_value' assert cfg.option('val2').value.get() == 'new_value'
#FIXME cache: cfg.option('val1').information.set('information', 'new_value2') cfg.option('val1').information.set('information', 'new_value2')
#assert cfg.option('val2').value.get() == 'new_value2' assert cfg.option('val2').value.get() == 'new_value2'
def test_callback_value_tuple(config_type): def test_callback_value_tuple(config_type):

View file

@ -391,10 +391,10 @@ def manager_callback(callback: Callable,
else: else:
option_bag = None option_bag = None
try: try:
return config_bag.context.impl_get_information(option_bag, return config_bag.context.get_values().get_information(option_bag,
param.information_name, param.information_name,
param.default_value, param.default_value,
) )
except ValueError as err: except ValueError as err:
raise ConfigError(_('option "{}" cannot be calculated: {}').format(option.impl_get_display_name(), raise ConfigError(_('option "{}" cannot be calculated: {}').format(option.impl_get_display_name(),
str(err), str(err),

View file

@ -591,11 +591,10 @@ class _CommonConfig(_SubConfig):
:param value: information's value (ex: "the help string") :param value: information's value (ex: "the help string")
""" """
self._impl_values.set_information(None, # pylint: disable=no-member self._impl_values.set_information(None, # pylint: disable=no-member
key, key,
value, value,
) )
cache = self.get_description()._cache_dependencies_information.get(key, []) # pylint: disable=protected-access for option in self.get_description()._cache_dependencies_information.get(key, []): # pylint: disable=protected-access
for option in cache:
option_bag = OptionBag(option, option_bag = OptionBag(option,
None, None,
config_bag, config_bag,
@ -604,7 +603,6 @@ class _CommonConfig(_SubConfig):
self.reset_cache(option_bag) self.reset_cache(option_bag)
def impl_get_information(self, def impl_get_information(self,
option_bag,
key, key,
default, default,
): ):
@ -612,7 +610,7 @@ class _CommonConfig(_SubConfig):
:param key: the item string (ex: "help") :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, key,
default, default,
) )

View file

@ -329,13 +329,7 @@ class BaseOption(Base):
""" """
return False return False
def get_dependencies_information(self, def get_dependencies_information(self) -> List[str]:
itself=False,
) -> List[str]:
"""get dependencies information """get dependencies information
""" """
if itself: return getattr(self, '_dependencies_information', {})
idx = 1
else:
idx = 0
return getattr(self, '_dependencies_information', [[], []])[idx]

View file

@ -65,7 +65,6 @@ class Option(BaseOption):
warnings_only: bool=False, warnings_only: bool=False,
extra: Optional[Dict]=None): extra: Optional[Dict]=None):
_setattr = object.__setattr__ _setattr = object.__setattr__
_dependencies_information = [[], []]
if not multi and default_multi is not None: if not multi and default_multi is not None:
raise ValueError(_("default_multi is set whereas multi is False" raise ValueError(_("default_multi is set whereas multi is False"
" in option: {0}").format(name)) " in option: {0}").format(name))
@ -101,15 +100,7 @@ class Option(BaseOption):
for validator in validators: for validator in validators:
if __debug__ and not isinstance(validator, Calculation): if __debug__ and not isinstance(validator, Calculation):
raise ValueError(_('validators must be a Calculation for "{}"').format(name)) raise ValueError(_('validators must be a Calculation for "{}"').format(name))
for param in chain(validator.params.args, validator.params.kwargs.values()): self.value_dependency(validator)
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._validators = tuple(validators) self._validators = tuple(validators)
if extra is not None and extra != {}: if extra is not None and extra != {}:
_setattr(self, '_extra', extra) _setattr(self, '_extra', extra)
@ -166,33 +157,29 @@ class Option(BaseOption):
check_error=False, check_error=False,
loaded=True, loaded=True,
) )
self.value_dependencies(default, _dependencies_information) self.value_dependencies(default)
if (is_multi and default != []) or \ if (is_multi and default != []) or \
(not is_multi and default is not None): (not is_multi and default is not None):
if is_multi and isinstance(default, list): if is_multi and isinstance(default, list):
default = tuple(default) default = tuple(default)
_setattr(self, '_default', default) _setattr(self, '_default', default)
if _dependencies_information[0] or _dependencies_information[1]:
self._dependencies_information = _dependencies_information
def value_dependencies(self, def value_dependencies(self,
value: Any, value: Any,
_dependencies_information: List[str],
) -> Any: ) -> Any:
"""parse dependancies to add dependencies """parse dependancies to add dependencies
""" """
if isinstance(value, list): if isinstance(value, list):
for val in value: for val in value:
if isinstance(value, list): if isinstance(value, list):
self.value_dependencies(val, _dependencies_information) self.value_dependencies(val)
elif isinstance(value, Calculation): elif isinstance(value, Calculation):
self.value_dependency(val, _dependencies_information) self.value_dependency(val)
elif isinstance(value, Calculation): elif isinstance(value, Calculation):
self.value_dependency(value, _dependencies_information) self.value_dependency(value)
def value_dependency(self, def value_dependency(self,
value: Any, value: Any,
_dependencies_information: List[str],
) -> Any: ) -> Any:
"""parse dependancy to add dependencies """parse dependancy to add dependencies
""" """
@ -200,10 +187,19 @@ class Option(BaseOption):
if isinstance(param, ParamOption): if isinstance(param, ParamOption):
# pylint: disable=protected-access # pylint: disable=protected-access
param.option._add_dependency(self) param.option._add_dependency(self)
elif isinstance(param, ParamSelfInformation): self._has_dependency = True
_dependencies_information[1].append(param.information_name)
elif isinstance(param, ParamInformation): 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 # option's information

View file

@ -88,8 +88,9 @@ class CacheOptionDescription(BaseOption):
display_name, display_name,
) )
else: else:
for information in option.get_dependencies_information(): for information, options in option.get_dependencies_information().items():
dependencies_information.setdefault(information, []).append(option) if None in options:
dependencies_information.setdefault(information, []).append(option)
if not option.impl_is_symlinkoption(): if not option.impl_is_symlinkoption():
properties = option.impl_getproperties() properties = option.impl_getproperties()
if 'force_store_value' in properties: if 'force_store_value' in properties:

View file

@ -658,8 +658,14 @@ class Values:
self._informations.setdefault(path, {})[key] = value self._informations.setdefault(path, {})[key] = value
if path is None: if path is None:
return return
if key in option_bag.option.get_dependencies_information(itself=True): for key, options in option_bag.option.get_dependencies_information().items():
option_bag.config_bag.context.reset_cache(option_bag) 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, def get_information(self,
option_bag, option_bag,