Compare commits

...

2 commits

5 changed files with 21 additions and 24 deletions

View file

@ -11,7 +11,7 @@ from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, Leadership, Config, undefined, \
Calculation, Params, ParamOption, ParamValue, ParamIndex, \
calc_value, calc_value_property_help
calc_value, calc_value_property_help, ParamInformation
from tiramisu.error import PropertiesOptionError
import warnings
from .config import config_type, get_config
@ -894,3 +894,18 @@ def test_settings_list_with_follower():
cfg = Config(OptionDescription('root', 'root', [descr]))
cfg.property.read_write()
assert len(cfg.option('root').list('all')) == 2
def return_none(*args):
return
def test_settings_disable_set_information(config_type):
opt1 = StrOption('opt1', '', ['val'], multi=True)
opt2 = StrOption('opt2', '', default_multi='test', validators=[Calculation(return_none, Params((ParamInformation('key'))))], properties=frozenset([Calculation(return_none, Params((ParamInformation('key'))))]), multi=True)
od2 = Leadership('leadership', '', [opt1, opt2])
od1 = OptionDescription('root', '', [od2])
cfg = Config(od1)
cfg.property.read_only()
cfg.information.set('key', 'val')
assert cfg.value.dict() == {'leadership.opt1': [{'leadership.opt1': 'val', 'leadership.opt2': 'test'}]}

View file

@ -180,7 +180,6 @@ class Calculation:
def execute(self,
option_bag: OptionBag,
leadership_must_have_index: bool=False,
orig_value: Any=undefined,
allow_value_error: bool=False,
force_value_warning: bool=False,
@ -191,7 +190,6 @@ class Calculation:
callback_params=self.params,
index=option_bag.index,
config_bag=option_bag.config_bag,
leadership_must_have_index=leadership_must_have_index,
orig_value=orig_value,
allow_value_error=allow_value_error,
force_value_warning=force_value_warning,
@ -200,12 +198,10 @@ class Calculation:
def help(self,
option_bag: OptionBag,
leadership_must_have_index: bool=False,
for_settings: bool=False,
) -> str:
if not self.help_function:
return self.execute(option_bag,
leadership_must_have_index=leadership_must_have_index,
for_settings=for_settings,
)
return carry_out_calculation(option_bag.option,
@ -213,22 +209,16 @@ class Calculation:
callback_params=self.params,
index=option_bag.index,
config_bag=option_bag.config_bag,
leadership_must_have_index=leadership_must_have_index,
for_settings=for_settings,
)
class Break(Exception):
pass
def manager_callback(callback: Callable,
param: Param,
option,
index: Optional[int],
orig_value,
config_bag: ConfigBag,
leadership_must_have_index: bool,
for_settings: bool,
) -> Any:
"""replace Param by true value"""
@ -419,8 +409,6 @@ def manager_callback(callback: Callable,
return option.impl_getsuffix()
if isinstance(param, ParamSelfOption):
if leadership_must_have_index and option.impl_is_follower() and index is None:
raise Break()
value = calc_self(param,
option,
index,
@ -473,8 +461,6 @@ def manager_callback(callback: Callable,
suffix,
dynopt)
callbk_options.append(doption)
if leadership_must_have_index and callbk_option.impl_is_follower() and index is None:
raise Break()
if callbk_options is None:
callbk_options = [callbk_option]
values = None
@ -518,7 +504,6 @@ def carry_out_calculation(option,
index: Optional[int],
config_bag: Optional[ConfigBag],
orig_value=undefined,
leadership_must_have_index: bool=False,
allow_value_error: bool=False,
force_value_warning: bool=False,
for_settings: bool=False,
@ -554,7 +539,6 @@ def carry_out_calculation(option,
index,
orig_value,
config_bag,
leadership_must_have_index,
for_settings,
)
if key is None:
@ -569,8 +553,6 @@ def carry_out_calculation(option,
args.append({'propertyerror': str(err)})
else:
kwargs[key] = {'propertyerror': str(err)}
except Break:
continue
ret = calculate(option,
callback,
allow_value_error,

View file

@ -599,6 +599,7 @@ class _CommonConfig(_SubConfig):
option_bag = OptionBag(option,
None,
config_bag,
properties=None,
)
self.reset_cache(option_bag)

View file

@ -316,14 +316,15 @@ class Option(BaseOption):
kwargs['orig_value'] = value
validator.execute(soption_bag,
leadership_must_have_index=True,
**kwargs)
**kwargs,
)
except ValueWarning as warn:
warnings.warn_explicit(ValueWarning(val,
self.get_type(),
self,
str(warn),
_index),
_index,
),
ValueWarning,
self.__class__.__name__, 319)

View file

@ -491,12 +491,10 @@ class Settings:
elif apply_requires:
if not help_property:
new_prop = prop.execute(option_bag,
leadership_must_have_index=True,
for_settings=True,
)
else:
new_prop = prop.help(option_bag,
leadership_must_have_index=True,
for_settings=True,
)
if isinstance(new_prop, str):