Compare commits
2 commits
3641eb39d8
...
3e6b90bd9c
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e6b90bd9c | |||
| 460039386a |
5 changed files with 21 additions and 24 deletions
|
|
@ -11,7 +11,7 @@ from tiramisu.setting import owners, groups
|
||||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||||
StrOption, OptionDescription, Leadership, Config, undefined, \
|
StrOption, OptionDescription, Leadership, Config, undefined, \
|
||||||
Calculation, Params, ParamOption, ParamValue, ParamIndex, \
|
Calculation, Params, ParamOption, ParamValue, ParamIndex, \
|
||||||
calc_value, calc_value_property_help
|
calc_value, calc_value_property_help, ParamInformation
|
||||||
from tiramisu.error import PropertiesOptionError
|
from tiramisu.error import PropertiesOptionError
|
||||||
import warnings
|
import warnings
|
||||||
from .config import config_type, get_config
|
from .config import config_type, get_config
|
||||||
|
|
@ -894,3 +894,18 @@ def test_settings_list_with_follower():
|
||||||
cfg = Config(OptionDescription('root', 'root', [descr]))
|
cfg = Config(OptionDescription('root', 'root', [descr]))
|
||||||
cfg.property.read_write()
|
cfg.property.read_write()
|
||||||
assert len(cfg.option('root').list('all')) == 2
|
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'}]}
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,6 @@ class Calculation:
|
||||||
|
|
||||||
def execute(self,
|
def execute(self,
|
||||||
option_bag: OptionBag,
|
option_bag: OptionBag,
|
||||||
leadership_must_have_index: bool=False,
|
|
||||||
orig_value: Any=undefined,
|
orig_value: Any=undefined,
|
||||||
allow_value_error: bool=False,
|
allow_value_error: bool=False,
|
||||||
force_value_warning: bool=False,
|
force_value_warning: bool=False,
|
||||||
|
|
@ -191,7 +190,6 @@ class Calculation:
|
||||||
callback_params=self.params,
|
callback_params=self.params,
|
||||||
index=option_bag.index,
|
index=option_bag.index,
|
||||||
config_bag=option_bag.config_bag,
|
config_bag=option_bag.config_bag,
|
||||||
leadership_must_have_index=leadership_must_have_index,
|
|
||||||
orig_value=orig_value,
|
orig_value=orig_value,
|
||||||
allow_value_error=allow_value_error,
|
allow_value_error=allow_value_error,
|
||||||
force_value_warning=force_value_warning,
|
force_value_warning=force_value_warning,
|
||||||
|
|
@ -200,12 +198,10 @@ class Calculation:
|
||||||
|
|
||||||
def help(self,
|
def help(self,
|
||||||
option_bag: OptionBag,
|
option_bag: OptionBag,
|
||||||
leadership_must_have_index: bool=False,
|
|
||||||
for_settings: bool=False,
|
for_settings: bool=False,
|
||||||
) -> str:
|
) -> str:
|
||||||
if not self.help_function:
|
if not self.help_function:
|
||||||
return self.execute(option_bag,
|
return self.execute(option_bag,
|
||||||
leadership_must_have_index=leadership_must_have_index,
|
|
||||||
for_settings=for_settings,
|
for_settings=for_settings,
|
||||||
)
|
)
|
||||||
return carry_out_calculation(option_bag.option,
|
return carry_out_calculation(option_bag.option,
|
||||||
|
|
@ -213,22 +209,16 @@ class Calculation:
|
||||||
callback_params=self.params,
|
callback_params=self.params,
|
||||||
index=option_bag.index,
|
index=option_bag.index,
|
||||||
config_bag=option_bag.config_bag,
|
config_bag=option_bag.config_bag,
|
||||||
leadership_must_have_index=leadership_must_have_index,
|
|
||||||
for_settings=for_settings,
|
for_settings=for_settings,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Break(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def manager_callback(callback: Callable,
|
def manager_callback(callback: Callable,
|
||||||
param: Param,
|
param: Param,
|
||||||
option,
|
option,
|
||||||
index: Optional[int],
|
index: Optional[int],
|
||||||
orig_value,
|
orig_value,
|
||||||
config_bag: ConfigBag,
|
config_bag: ConfigBag,
|
||||||
leadership_must_have_index: bool,
|
|
||||||
for_settings: bool,
|
for_settings: bool,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""replace Param by true value"""
|
"""replace Param by true value"""
|
||||||
|
|
@ -419,8 +409,6 @@ def manager_callback(callback: Callable,
|
||||||
return option.impl_getsuffix()
|
return option.impl_getsuffix()
|
||||||
|
|
||||||
if isinstance(param, ParamSelfOption):
|
if isinstance(param, ParamSelfOption):
|
||||||
if leadership_must_have_index and option.impl_is_follower() and index is None:
|
|
||||||
raise Break()
|
|
||||||
value = calc_self(param,
|
value = calc_self(param,
|
||||||
option,
|
option,
|
||||||
index,
|
index,
|
||||||
|
|
@ -473,8 +461,6 @@ def manager_callback(callback: Callable,
|
||||||
suffix,
|
suffix,
|
||||||
dynopt)
|
dynopt)
|
||||||
callbk_options.append(doption)
|
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:
|
if callbk_options is None:
|
||||||
callbk_options = [callbk_option]
|
callbk_options = [callbk_option]
|
||||||
values = None
|
values = None
|
||||||
|
|
@ -518,7 +504,6 @@ def carry_out_calculation(option,
|
||||||
index: Optional[int],
|
index: Optional[int],
|
||||||
config_bag: Optional[ConfigBag],
|
config_bag: Optional[ConfigBag],
|
||||||
orig_value=undefined,
|
orig_value=undefined,
|
||||||
leadership_must_have_index: bool=False,
|
|
||||||
allow_value_error: bool=False,
|
allow_value_error: bool=False,
|
||||||
force_value_warning: bool=False,
|
force_value_warning: bool=False,
|
||||||
for_settings: bool=False,
|
for_settings: bool=False,
|
||||||
|
|
@ -554,7 +539,6 @@ def carry_out_calculation(option,
|
||||||
index,
|
index,
|
||||||
orig_value,
|
orig_value,
|
||||||
config_bag,
|
config_bag,
|
||||||
leadership_must_have_index,
|
|
||||||
for_settings,
|
for_settings,
|
||||||
)
|
)
|
||||||
if key is None:
|
if key is None:
|
||||||
|
|
@ -569,8 +553,6 @@ def carry_out_calculation(option,
|
||||||
args.append({'propertyerror': str(err)})
|
args.append({'propertyerror': str(err)})
|
||||||
else:
|
else:
|
||||||
kwargs[key] = {'propertyerror': str(err)}
|
kwargs[key] = {'propertyerror': str(err)}
|
||||||
except Break:
|
|
||||||
continue
|
|
||||||
ret = calculate(option,
|
ret = calculate(option,
|
||||||
callback,
|
callback,
|
||||||
allow_value_error,
|
allow_value_error,
|
||||||
|
|
|
||||||
|
|
@ -599,6 +599,7 @@ class _CommonConfig(_SubConfig):
|
||||||
option_bag = OptionBag(option,
|
option_bag = OptionBag(option,
|
||||||
None,
|
None,
|
||||||
config_bag,
|
config_bag,
|
||||||
|
properties=None,
|
||||||
)
|
)
|
||||||
self.reset_cache(option_bag)
|
self.reset_cache(option_bag)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -316,14 +316,15 @@ class Option(BaseOption):
|
||||||
kwargs['orig_value'] = value
|
kwargs['orig_value'] = value
|
||||||
|
|
||||||
validator.execute(soption_bag,
|
validator.execute(soption_bag,
|
||||||
leadership_must_have_index=True,
|
**kwargs,
|
||||||
**kwargs)
|
)
|
||||||
except ValueWarning as warn:
|
except ValueWarning as warn:
|
||||||
warnings.warn_explicit(ValueWarning(val,
|
warnings.warn_explicit(ValueWarning(val,
|
||||||
self.get_type(),
|
self.get_type(),
|
||||||
self,
|
self,
|
||||||
str(warn),
|
str(warn),
|
||||||
_index),
|
_index,
|
||||||
|
),
|
||||||
ValueWarning,
|
ValueWarning,
|
||||||
self.__class__.__name__, 319)
|
self.__class__.__name__, 319)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -491,12 +491,10 @@ class Settings:
|
||||||
elif apply_requires:
|
elif apply_requires:
|
||||||
if not help_property:
|
if not help_property:
|
||||||
new_prop = prop.execute(option_bag,
|
new_prop = prop.execute(option_bag,
|
||||||
leadership_must_have_index=True,
|
|
||||||
for_settings=True,
|
for_settings=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
new_prop = prop.help(option_bag,
|
new_prop = prop.help(option_bag,
|
||||||
leadership_must_have_index=True,
|
|
||||||
for_settings=True,
|
for_settings=True,
|
||||||
)
|
)
|
||||||
if isinstance(new_prop, str):
|
if isinstance(new_prop, str):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue