Remove 'build_actions' in 'apply_requires', now 'validate_requires_arg' build requires with tuple of tuple
New _requires format: - requirement (like old format) - tuple of requirements, each items are a tuple of requirement with same action
This commit is contained in:
parent
9b134c3aa7
commit
b8bfa02e02
|
@ -813,11 +813,13 @@ class OptionDescription(BaseInformation):
|
|||
|
||||
def validate_requires_arg(requires, name):
|
||||
"""check malformed requirements
|
||||
and tranform dict to tuple"""
|
||||
and tranform dict to internal tuple
|
||||
"""
|
||||
if requires is None:
|
||||
return None
|
||||
ret_requires = []
|
||||
ret_requires = {}
|
||||
config_action = {}
|
||||
|
||||
for require in requires:
|
||||
if not type(require) == dict:
|
||||
raise ValueError(_("malformed requirements type for option:"
|
||||
|
@ -868,7 +870,7 @@ def validate_requires_arg(requires, name):
|
|||
else:
|
||||
config_action[action] = inverse
|
||||
|
||||
ret_requires.append((option, expected, action, inverse, transitive,
|
||||
same_action))
|
||||
ret_requires.setdefault(action, []).append((option, expected, action,
|
||||
inverse, transitive, same_action))
|
||||
|
||||
return tuple(ret_requires)
|
||||
return tuple(tuple(ret) for ret in ret_requires.values())
|
||||
|
|
|
@ -214,7 +214,7 @@ class Setting(object):
|
|||
if exp < created:
|
||||
return props
|
||||
if is_apply_req:
|
||||
apply_requires(opt, self.context)
|
||||
self.apply_requires(opt)
|
||||
props = self._properties.get(opt, opt._properties)
|
||||
self._set_cache(opt, props, exp)
|
||||
return props
|
||||
|
@ -331,27 +331,16 @@ class Setting(object):
|
|||
else:
|
||||
self._cache.clear()
|
||||
|
||||
|
||||
def apply_requires(opt, config):
|
||||
def apply_requires(self, opt):
|
||||
"carries out the jit (just in time requirements between options"
|
||||
if opt._requires is None:
|
||||
return
|
||||
|
||||
def build_actions(requires):
|
||||
"action are hide, show, enable, disable..."
|
||||
trigger_actions = {}
|
||||
for require in requires:
|
||||
action = require[2]
|
||||
trigger_actions.setdefault(action, []).append(require)
|
||||
return trigger_actions
|
||||
|
||||
# filters the callbacks
|
||||
settings = config.cfgimpl_get_settings()
|
||||
setting = Property(settings, settings._get_properties(opt, False), opt)
|
||||
trigger_actions = build_actions(opt._requires)
|
||||
descr = config.cfgimpl_get_context().cfgimpl_get_description()
|
||||
setting = Property(self, self._get_properties(opt, False), opt)
|
||||
descr = self.context.cfgimpl_get_description()
|
||||
optpath = descr.impl_get_path_by_opt(opt)
|
||||
for requires in trigger_actions.values():
|
||||
for requires in opt._requires:
|
||||
matches = False
|
||||
for require in requires:
|
||||
option, expected, action, inverse, transitive, same_action = require
|
||||
|
@ -361,7 +350,7 @@ def apply_requires(opt, config):
|
|||
"imbrication detected for option: '{0}' "
|
||||
"with requirement on: '{1}'").format(optpath, path))
|
||||
try:
|
||||
value = config.cfgimpl_get_context()._getattr(path, force_permissive=True)
|
||||
value = self.context._getattr(path, force_permissive=True)
|
||||
except PropertiesOptionError, err:
|
||||
if not transitive:
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue