separate config properties and properties in option + better properties check

This commit is contained in:
Emmanuel Garette 2018-11-29 22:08:50 +01:00
parent fee8997f13
commit a30eaacb1f
2 changed files with 24 additions and 12 deletions

View File

@ -174,6 +174,19 @@ class _TiramisuOptionOptionDescription(CommonTiramisuOption):
option = self._option_bag.option option = self._option_bag.option
return option.impl_is_optiondescription() return option.impl_is_optiondescription()
def properties(self,
only_raises=False):
"""Get properties for an option"""
settings = self._option_bag.config_bag.context.cfgimpl_get_settings()
properties = settings.getproperties(self._option_bag,
apply_requires=False)
if not only_raises:
return properties
# do not check cache properties/permissives which are not save (unrestraint, ...)
return settings.calc_raises_properties(properties,
settings.get_context_properties(),
settings.get_context_properties())
class _TiramisuOptionOption(_TiramisuOptionOptionDescription): class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
"""Manage option""" """Manage option"""
@ -293,21 +306,17 @@ class TiramisuOptionProperty(CommonTiramisuOption):
self._settings = option_bag.config_bag.context.cfgimpl_get_settings() self._settings = option_bag.config_bag.context.cfgimpl_get_settings()
def get(self, def get(self,
apply_requires=True,
only_raises=False): only_raises=False):
"""Get properties for an option""" """Get properties for an option"""
option = self._option_bag.option option = self._option_bag.option
if apply_requires:
self._test_slave_index() self._test_slave_index()
properties = self._option_bag.properties properties = self._option_bag.properties
else:
properties = self._settings.getproperties(self._option_bag,
apply_requires=False)
if not only_raises: if not only_raises:
return properties return properties
# do not check cache properties/permissives which are not save (unrestraint, ...)
return self._settings.calc_raises_properties(properties, return self._settings.calc_raises_properties(properties,
self._option_bag.config_bag.properties, self._settings.get_context_properties(),
self._option_bag.config_bag.permissives) self._settings.get_context_properties())
def add(self, prop): def add(self, prop):
"""Add new property for an option""" """Add new property for an option"""

View File

@ -21,7 +21,7 @@
from typing import Any, Optional, Union, Callable, Dict, List from typing import Any, Optional, Union, Callable, Dict, List
from .error import PropertiesOptionError, ConfigError, SlaveError from .error import PropertiesOptionError, ConfigError, SlaveError, RequirementError
from .i18n import _ from .i18n import _
from .setting import undefined, ConfigBag, OptionBag, Undefined from .setting import undefined, ConfigBag, OptionBag, Undefined
from .storage import get_default_values_storages, get_default_settings_storages from .storage import get_default_values_storages, get_default_settings_storages
@ -89,9 +89,12 @@ def manager_callback(callbk: Union[ParamOption, ParamValue],
if with_index: if with_index:
return value[index] return value[index]
return value return value
except PropertiesOptionError as err: except (PropertiesOptionError, RequirementError) as err:
# raise because must not add value None in carry_out_calculation
if callbk.notraisepropertyerror: if callbk.notraisepropertyerror:
raise err raise PropertiesOptionError(option_bag,
None,
None)
raise ConfigError(_('unable to carry out a calculation for "{}"' raise ConfigError(_('unable to carry out a calculation for "{}"'
', {}').format(option.impl_get_display_name(), err)) ', {}').format(option.impl_get_display_name(), err))