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 = 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):

View file

@ -391,7 +391,7 @@ def manager_callback(callback: Callable,
else:
option_bag = None
try:
return config_bag.context.impl_get_information(option_bag,
return config_bag.context.get_values().get_information(option_bag,
param.information_name,
param.default_value,
)

View file

@ -594,8 +594,7 @@ class _CommonConfig(_SubConfig):
key,
value,
)
cache = self.get_description()._cache_dependencies_information.get(key, []) # pylint: disable=protected-access
for option in cache:
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,
)

View file

@ -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', {})

View file

@ -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

View file

@ -88,7 +88,8 @@ class CacheOptionDescription(BaseOption):
display_name,
)
else:
for information in option.get_dependencies_information():
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()

View file

@ -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,