consistency is now simple validation
This commit is contained in:
@ -25,14 +25,12 @@ from typing import Optional, Iterator, Union, List
|
||||
from ..i18n import _
|
||||
from ..setting import ConfigBag, OptionBag, groups, undefined, owners, Undefined
|
||||
from .baseoption import BaseOption
|
||||
from .option import ALLOWED_CONST_LIST
|
||||
from .syndynoptiondescription import SynDynOptionDescription, SynDynLeadership
|
||||
from ..error import ConfigError, ConflictError
|
||||
|
||||
|
||||
class CacheOptionDescription(BaseOption):
|
||||
__slots__ = ('_cache_consistencies',
|
||||
'_cache_force_store_values')
|
||||
__slots__ = ('_cache_force_store_values',)
|
||||
|
||||
def impl_already_build_caches(self) -> bool:
|
||||
return self.impl_is_readonly()
|
||||
@ -101,60 +99,10 @@ class CacheOptionDescription(BaseOption):
|
||||
'"force_metaconfig_on_freeze" '
|
||||
'property without "frozen"'
|
||||
'').format(option.impl_get_display_name()))
|
||||
for cons_id, func, all_cons_opts, params in option.get_consistencies():
|
||||
option._valid_consistencies(all_cons_opts[1:], init=False)
|
||||
if func not in ALLOWED_CONST_LIST and is_multi:
|
||||
if __debug__ and not option.impl_get_leadership():
|
||||
raise ConfigError(_('malformed consistency option "{0}" '
|
||||
'must be in same leadership').format(
|
||||
option.impl_getname()))
|
||||
leadership = option.impl_get_leadership()
|
||||
for weak_opt in all_cons_opts:
|
||||
opt = weak_opt()
|
||||
if __debug__ and func not in ALLOWED_CONST_LIST and is_multi:
|
||||
if not opt.impl_get_leadership():
|
||||
raise ConfigError(_('malformed consistency option "{0}" '
|
||||
'must not be a multi for "{1}"').format(
|
||||
option.impl_getname(), opt.impl_getname()))
|
||||
elif leadership != opt.impl_get_leadership():
|
||||
raise ConfigError(_('malformed consistency option "{0}" '
|
||||
'must be in same leadership as "{1}"').format(
|
||||
option.impl_getname(), opt.impl_getname()))
|
||||
_consistencies.setdefault(weak_opt,
|
||||
[]).append((_consistencies_id,
|
||||
func,
|
||||
all_cons_opts,
|
||||
params))
|
||||
_consistencies_id += 1
|
||||
# if context is set to callback, must be reset each time a value change
|
||||
if hasattr(option, '_has_calc_context'):
|
||||
self._add_dependency(option)
|
||||
|
||||
if __debug__:
|
||||
is_follower = None
|
||||
if is_multi:
|
||||
all_requires = option.impl_getrequires()
|
||||
for requires in all_requires:
|
||||
for require in requires:
|
||||
#if option in require is a multi:
|
||||
# * option in require must be a leader or a follower
|
||||
# * current option must be a follower (and only a follower)
|
||||
# * option in require and current option must be in same leadership
|
||||
for require_opt, values in require[0]:
|
||||
if not isinstance(require_opt, tuple) and require_opt.impl_is_multi():
|
||||
if is_follower is None:
|
||||
is_follower = option.impl_is_follower()
|
||||
if is_follower:
|
||||
leadership = option.impl_get_leadership()
|
||||
if is_follower and require_opt.impl_get_leadership():
|
||||
if leadership != require_opt.impl_get_leadership():
|
||||
raise ValueError(_('malformed requirements option "{0}" '
|
||||
'must be in same leadership for "{1}"').format(
|
||||
require_opt.impl_getname(), option.impl_getname()))
|
||||
else:
|
||||
raise ValueError(_('malformed requirements option "{0}" '
|
||||
'must not be a multi for "{1}"').format(
|
||||
require_opt.impl_getname(), option.impl_getname()))
|
||||
if option.impl_is_readonly():
|
||||
raise ConflictError(_('duplicate option: {0}').format(option))
|
||||
if not self.impl_is_readonly() and display_name:
|
||||
@ -162,15 +110,6 @@ class CacheOptionDescription(BaseOption):
|
||||
option._path = subpath
|
||||
option._set_readonly()
|
||||
if init:
|
||||
if _consistencies != {}:
|
||||
self._cache_consistencies = {}
|
||||
for weak_opt, cons in _consistencies.items():
|
||||
opt = weak_opt()
|
||||
if __debug__ and opt not in cache_option:
|
||||
raise ConfigError(_('consistency with option {0} '
|
||||
'which is not in Config').format(
|
||||
opt.impl_getname()))
|
||||
self._cache_consistencies[opt] = tuple(cons)
|
||||
self._cache_force_store_values = force_store_values
|
||||
self._path = self._name
|
||||
self._set_readonly()
|
||||
@ -275,7 +214,6 @@ class OptionDescription(OptionDescriptionWalk):
|
||||
name: str,
|
||||
doc: str,
|
||||
children: List[BaseOption],
|
||||
requires=None,
|
||||
properties=None) -> None:
|
||||
"""
|
||||
:param children: a list of options (including optiondescriptions)
|
||||
@ -285,7 +223,6 @@ class OptionDescription(OptionDescriptionWalk):
|
||||
'must be a list').format(name)
|
||||
super().__init__(name,
|
||||
doc=doc,
|
||||
requires=requires,
|
||||
properties=properties)
|
||||
child_names = []
|
||||
if __debug__:
|
||||
|
Reference in New Issue
Block a user