deletion of the cache when changinf information for an option if needed
This commit is contained in:
parent
3e6b90bd9c
commit
aa79d9a710
7 changed files with 41 additions and 46 deletions
|
@ -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):
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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', {})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue