better propertyerror message
This commit is contained in:
@ -20,7 +20,7 @@ from copy import copy
|
||||
from logging import getLogger
|
||||
import weakref
|
||||
from .error import (RequirementError, PropertiesOptionError,
|
||||
ConstError, ConfigError)
|
||||
ConstError, ConfigError, display_list)
|
||||
from .i18n import _
|
||||
|
||||
|
||||
@ -113,6 +113,7 @@ log = getLogger('tiramisu')
|
||||
#FIXME
|
||||
#import logging
|
||||
#logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
|
||||
debug = False
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
@ -394,7 +395,7 @@ class Settings(object):
|
||||
if opt.impl_is_multi() and not opt.impl_is_master_slaves('slave'):
|
||||
props.add('empty')
|
||||
if apply_requires:
|
||||
requires = self.apply_requires(opt, path, setting_properties, index)
|
||||
requires = self.apply_requires(opt, path, setting_properties, index, False)
|
||||
if requires != set([]):
|
||||
props = copy(props)
|
||||
props |= requires
|
||||
@ -441,7 +442,7 @@ class Settings(object):
|
||||
value=None, force_permissive=False,
|
||||
setting_properties=undefined,
|
||||
self_properties=undefined,
|
||||
index=None):
|
||||
index=None, debug=False):
|
||||
"""
|
||||
validation upon the properties related to `opt_or_descr`
|
||||
|
||||
@ -496,22 +497,30 @@ class Settings(object):
|
||||
# at this point an option should not remain in properties
|
||||
if properties != frozenset():
|
||||
props = list(properties)
|
||||
datas = {'opt': opt_or_descr, 'path': path, 'setting_properties': setting_properties,
|
||||
'index': index, 'debug': True}
|
||||
if is_descr:
|
||||
opt_type = 'optiondescription'
|
||||
else:
|
||||
opt_type = 'option'
|
||||
if 'frozen' in properties:
|
||||
return PropertiesOptionError(_('cannot change the value for '
|
||||
'option {0} this option is'
|
||||
' frozen').format(
|
||||
opt_or_descr.impl_getname()),
|
||||
props)
|
||||
props, self, datas, opt_type)
|
||||
else:
|
||||
if is_descr:
|
||||
opt_type = 'optiondescription'
|
||||
if len(props) == 1:
|
||||
prop_msg = 'property'
|
||||
else:
|
||||
opt_type = 'option'
|
||||
return PropertiesOptionError(_("trying to access to an {0} "
|
||||
"named: {1} with properties {2}"
|
||||
prop_msg = 'properties'
|
||||
return PropertiesOptionError(_("cannot access to {0} {1} "
|
||||
"because has {2} {3}"
|
||||
"").format(opt_type,
|
||||
opt_or_descr._name,
|
||||
str(props)), props)
|
||||
prop_msg,
|
||||
display_list(props)), props,
|
||||
self, datas, opt_type)
|
||||
|
||||
def setpermissive(self, permissive, opt=None, path=None):
|
||||
"""
|
||||
@ -571,7 +580,7 @@ class Settings(object):
|
||||
else:
|
||||
self._p_.reset_all_cache()
|
||||
|
||||
def apply_requires(self, opt, path, setting_properties, index):
|
||||
def apply_requires(self, opt, path, setting_properties, index, debug):
|
||||
"""carries out the jit (just in time) requirements between options
|
||||
|
||||
a requirement is a tuple of this form that comes from the option's
|
||||
@ -619,7 +628,10 @@ class Settings(object):
|
||||
return frozenset()
|
||||
|
||||
# filters the callbacks
|
||||
calc_properties = set()
|
||||
if debug:
|
||||
calc_properties = {}
|
||||
else:
|
||||
calc_properties = set()
|
||||
context = self._getcontext()
|
||||
for requires in opt.impl_getrequires():
|
||||
for require in requires:
|
||||
@ -650,17 +662,30 @@ class Settings(object):
|
||||
"{1} {2}").format(opt._name,
|
||||
reqpath,
|
||||
properties))
|
||||
orig_value = value
|
||||
# transitive action, force expected
|
||||
value = expected[0]
|
||||
inverse = False
|
||||
else:
|
||||
raise value
|
||||
else:
|
||||
orig_value = value
|
||||
if (not inverse and
|
||||
value in expected or
|
||||
inverse and value not in expected):
|
||||
calc_properties.add(action)
|
||||
# the calculation cannot be carried out
|
||||
break
|
||||
if debug:
|
||||
if isinstance(orig_value, PropertiesOptionError):
|
||||
for act, msg in orig_value._settings.apply_requires(**orig_value._datas).items():
|
||||
calc_properties.setdefault(action, []).extend(msg)
|
||||
else:
|
||||
if not inverse:
|
||||
msg = _("the value of {0} is {1}")
|
||||
else:
|
||||
msg = _("the value of {0} is not {1}")
|
||||
calc_properties.setdefault(action, []).append(msg.format(reqpath, display_list(expected, 'or')))
|
||||
else:
|
||||
calc_properties.add(action)
|
||||
break
|
||||
return calc_properties
|
||||
|
||||
def get_modified_properties(self):
|
||||
|
Reference in New Issue
Block a user