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:
Emmanuel Garette 2013-07-01 11:55:32 +02:00
parent 9b134c3aa7
commit b8bfa02e02
2 changed files with 48 additions and 57 deletions

View File

@ -813,11 +813,13 @@ class OptionDescription(BaseInformation):
def validate_requires_arg(requires, name): def validate_requires_arg(requires, name):
"""check malformed requirements """check malformed requirements
and tranform dict to tuple""" and tranform dict to internal tuple
"""
if requires is None: if requires is None:
return None return None
ret_requires = [] ret_requires = {}
config_action = {} config_action = {}
for require in requires: for require in requires:
if not type(require) == dict: if not type(require) == dict:
raise ValueError(_("malformed requirements type for option:" raise ValueError(_("malformed requirements type for option:"
@ -868,7 +870,7 @@ def validate_requires_arg(requires, name):
else: else:
config_action[action] = inverse config_action[action] = inverse
ret_requires.append((option, expected, action, inverse, transitive, ret_requires.setdefault(action, []).append((option, expected, action,
same_action)) inverse, transitive, same_action))
return tuple(ret_requires) return tuple(tuple(ret) for ret in ret_requires.values())

View File

@ -214,7 +214,7 @@ class Setting(object):
if exp < created: if exp < created:
return props return props
if is_apply_req: if is_apply_req:
apply_requires(opt, self.context) self.apply_requires(opt)
props = self._properties.get(opt, opt._properties) props = self._properties.get(opt, opt._properties)
self._set_cache(opt, props, exp) self._set_cache(opt, props, exp)
return props return props
@ -331,55 +331,44 @@ class Setting(object):
else: else:
self._cache.clear() self._cache.clear()
def apply_requires(self, opt):
"carries out the jit (just in time requirements between options"
if opt._requires is None:
return
def apply_requires(opt, config): # filters the callbacks
"carries out the jit (just in time requirements between options" setting = Property(self, self._get_properties(opt, False), opt)
if opt._requires is None: descr = self.context.cfgimpl_get_description()
return optpath = descr.impl_get_path_by_opt(opt)
for requires in opt._requires:
def build_actions(requires): matches = False
"action are hide, show, enable, disable..." for require in requires:
trigger_actions = {} option, expected, action, inverse, transitive, same_action = require
for require in requires: path = descr.impl_get_path_by_opt(option)
action = require[2] if path == optpath or path.startswith(optpath + '.'):
trigger_actions.setdefault(action, []).append(require) raise RequirementError(_("malformed requirements "
return trigger_actions "imbrication detected for option: '{0}' "
"with requirement on: '{1}'").format(optpath, path))
# filters the callbacks try:
settings = config.cfgimpl_get_settings() value = self.context._getattr(path, force_permissive=True)
setting = Property(settings, settings._get_properties(opt, False), opt) except PropertiesOptionError, err:
trigger_actions = build_actions(opt._requires) if not transitive:
descr = config.cfgimpl_get_context().cfgimpl_get_description() continue
optpath = descr.impl_get_path_by_opt(opt) properties = err.proptype
for requires in trigger_actions.values(): if same_action and action not in properties:
matches = False raise RequirementError(_("option '{0}' has requirement's property error: "
for require in requires: "{1} {2}").format(opt._name, path, properties))
option, expected, action, inverse, transitive, same_action = require #transitive action, force expected
path = descr.impl_get_path_by_opt(option) value = expected
if path == optpath or path.startswith(optpath + '.'): inverse = False
raise RequirementError(_("malformed requirements " except AttributeError:
"imbrication detected for option: '{0}' " raise AttributeError(_("required option not found: "
"with requirement on: '{1}'").format(optpath, path)) "{0}").format(path))
try: if not inverse and value == expected or inverse and value != expected:
value = config.cfgimpl_get_context()._getattr(path, force_permissive=True) matches = True
except PropertiesOptionError, err: setting.append(action)
if not transitive: ## the calculation cannot be carried out
continue break
properties = err.proptype # no requirement has been triggered, then just reverse the action
if same_action and action not in properties: if not matches:
raise RequirementError(_("option '{0}' has requirement's property error: " setting.remove(action)
"{1} {2}").format(opt._name, path, properties))
#transitive action, force expected
value = expected
inverse = False
except AttributeError:
raise AttributeError(_("required option not found: "
"{0}").format(path))
if not inverse and value == expected or inverse and value != expected:
matches = True
setting.append(action)
## the calculation cannot be carried out
break
# no requirement has been triggered, then just reverse the action
if not matches:
setting.remove(action)