can remove prefix in ValueOptionError
This commit is contained in:
@ -297,7 +297,9 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
if option_bag and option_bag.config_bag:
|
||||
self._settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
||||
|
||||
def get(self, apply_requires=True):
|
||||
def get(self,
|
||||
apply_requires=True,
|
||||
only_raises=False):
|
||||
"""Get properties for an option"""
|
||||
option = self._option_bag.option
|
||||
if apply_requires:
|
||||
@ -305,8 +307,12 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
properties = self._option_bag.properties
|
||||
else:
|
||||
properties = self._settings.getproperties(self._option_bag,
|
||||
apply_requires=False)
|
||||
return set(properties)
|
||||
apply_requires=False)
|
||||
if not only_raises:
|
||||
return properties
|
||||
return self._settings.calc_raises_properties(properties,
|
||||
self._option_bag.config_bag.properties,
|
||||
self._option_bag.config_bag.permissives)
|
||||
|
||||
def add(self, prop):
|
||||
"""Add new property for an option"""
|
||||
@ -335,7 +341,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
"""Reset all personalised properties"""
|
||||
option = self._option_bag.option
|
||||
self._settings.reset(self._option_bag,
|
||||
self._option_bag.config_bag.context)
|
||||
self._option_bag.config_bag.context)
|
||||
|
||||
|
||||
class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||
@ -1066,6 +1072,17 @@ class _TiramisuContextConfigReset():
|
||||
# Remove cache
|
||||
self._config_bag.context.cfgimpl_reset_cache(None, None)
|
||||
|
||||
def __call__(self,
|
||||
path: Optional[str]):
|
||||
"""select a child Tiramisu config"""
|
||||
if path is None:
|
||||
return Config(self._config_bag)
|
||||
spaths = path.split('.')
|
||||
config = self._config_bag.context
|
||||
for spath in spaths:
|
||||
config = config.getconfig(spath)
|
||||
return Config(config)
|
||||
|
||||
|
||||
class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
|
||||
"""Actions to Config"""
|
||||
@ -1166,7 +1183,7 @@ class TiramisuAPI(TiramisuHelp):
|
||||
return TiramisuAPI(config_bag)
|
||||
elif subfunc == 'unrestraint':
|
||||
config_bag = self._config_bag.copy()
|
||||
config_bag.properties = frozenset()
|
||||
config_bag.properties = frozenset(['cache'])
|
||||
return TiramisuAPI(config_bag)
|
||||
elif subfunc == 'config':
|
||||
config_type = self._config_bag.context.impl_type
|
||||
|
@ -185,5 +185,29 @@ class ValueWarning(UserWarning):
|
||||
super(ValueWarning, self).__init__(msg)
|
||||
|
||||
|
||||
class ValueOptionError(ValueError):
|
||||
def __init__(self,
|
||||
val,
|
||||
display_type,
|
||||
display_name,
|
||||
err_msg):
|
||||
self.prefix = _('"{0}" is an invalid {1} for "{2}"'
|
||||
'').format(val,
|
||||
display_type,
|
||||
display_name)
|
||||
self.err_msg = err_msg
|
||||
|
||||
def __str__(self):
|
||||
msg = self.prefix
|
||||
if self.err_msg:
|
||||
if msg:
|
||||
msg += ', {}'.format(self.err_msg)
|
||||
else:
|
||||
msg = self.err_msg
|
||||
if not msg:
|
||||
msg = _('invalid value')
|
||||
return msg
|
||||
|
||||
|
||||
class APIError(Exception):
|
||||
pass
|
||||
|
@ -28,7 +28,7 @@ from ..i18n import _
|
||||
from ..setting import log, undefined, OptionBag
|
||||
from ..autolib import carry_out_calculation
|
||||
from ..error import (ConfigError, ValueWarning, PropertiesOptionError,
|
||||
display_list)
|
||||
ValueOptionError, display_list)
|
||||
from ..function import Params, ParamValue
|
||||
ALLOWED_CONST_LIST = ['_cons_not_equal']
|
||||
|
||||
@ -350,14 +350,10 @@ class Option(OnlyOption):
|
||||
check_error,
|
||||
is_warnings_only)
|
||||
except ValueError as err:
|
||||
msg = _('"{0}" is an invalid {1} for "{2}"'
|
||||
'').format(val,
|
||||
self._display_name,
|
||||
option_bag.ori_option.impl_get_display_name())
|
||||
err_msg = '{0}'.format(err)
|
||||
if err_msg:
|
||||
msg += ', {}'.format(err_msg)
|
||||
raise ValueError(msg)
|
||||
raise ValueOptionError(val,
|
||||
self._display_name,
|
||||
option_bag.ori_option.impl_get_display_name(),
|
||||
'{0}'.format(err))
|
||||
|
||||
def _validate_calculator(self,
|
||||
callback,
|
||||
|
Reference in New Issue
Block a user