Compare commits
4 commits
dda10f76f8
...
fe108b1238
| Author | SHA1 | Date | |
|---|---|---|---|
| fe108b1238 | |||
| 050979f6d3 | |||
| faf694397a | |||
| a5870ee2ab |
18 changed files with 364 additions and 171 deletions
|
|
@ -402,12 +402,12 @@ def test_prefix_error():
|
|||
try:
|
||||
cfg.option('test1').value.set('yes')
|
||||
except Exception as err:
|
||||
assert str(err) == _('"{0}" is an invalid {1} for "{2}", which is not an integer').format('yes', _('integer'), 'test1')
|
||||
assert str(err) == _('"{0}" is an invalid {1} for "{2}", it\'s not an integer').format('yes', _('integer'), 'test1')
|
||||
try:
|
||||
cfg.option('test1').value.set('yes')
|
||||
except Exception as err:
|
||||
err.prefix = ''
|
||||
assert str(err) == _('which is not an integer')
|
||||
assert str(err) == _('it\'s not an integer')
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,18 @@ def return_true(value, param=None, identifier=None):
|
|||
raise ValueError('no value')
|
||||
|
||||
|
||||
def return_no_dyn(value):
|
||||
if value in [['val', 'val'], ['yes', 'yes']]:
|
||||
return
|
||||
raise ValueError('no value')
|
||||
|
||||
|
||||
def return_no_dyn_properties(value, identifier):
|
||||
idx = int(identifier)
|
||||
if idx and not value[idx - 1]:
|
||||
return 'disabled'
|
||||
|
||||
|
||||
def return_dynval(value='val', identifier=None):
|
||||
return value
|
||||
|
||||
|
|
@ -344,6 +356,17 @@ def test_prop_dyndescription_force_store_value():
|
|||
# assert not list_sessions()
|
||||
|
||||
|
||||
def test_prop_dyndescription_force_store_value_disabled():
|
||||
st = StrOption('st', '', properties=('force_store_value', 'disabled'))
|
||||
dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.property.read_write()
|
||||
assert parse_od_get(cfg.value.get()) == {}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
def test_prop_dyndescription_force_store_value_calculation_prefix():
|
||||
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', Calculation(return_list, Params(ParamIdentifier())) , properties=('force_store_value',))
|
||||
|
|
@ -1117,6 +1140,43 @@ def test_validator_dyndescription():
|
|||
# assert not list_sessions()
|
||||
|
||||
|
||||
def test_validator_param_self_option():
|
||||
out = StrOption('out', '', 'val')
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st_in = StrOption('st_in', '', Calculation(return_dynval, Params(ParamOption(out))))
|
||||
st = StrOption('st', '', Calculation(return_dynval, Params(ParamOption(st_in))), validators=[Calculation(return_no_dyn, Params((ParamSelfOption(dynamic=False),)))])
|
||||
dod = DynOptionDescription('dod', '', [st_in, st], identifiers=Calculation(return_list))
|
||||
od = OptionDescription('od', '', [dod, val1, out])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
assert cfg.option('od.dodval1.st').value.get() == 'val'
|
||||
with pytest.raises(ValueError):
|
||||
cfg.option('od.dodval1.st').value.set('no')
|
||||
cfg.option('od.out').value.set('yes')
|
||||
|
||||
|
||||
def test_properties_param_self_option():
|
||||
out = StrOption('out', '', 'val')
|
||||
val1 = StrOption('val1', '', ["0", "1", "2"], multi=True)
|
||||
disabled_property = Calculation(return_no_dyn_properties, Params((ParamSelfOption(dynamic=False), ParamIdentifier())))
|
||||
st = StrOption('st', '', None, properties=(disabled_property,))
|
||||
dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
|
||||
od = OptionDescription('od', '', [dod, val1, out])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.property.read_write()
|
||||
assert cfg.option('od.dod0.st').value.get() is None
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('od.dod1.st').value.get()
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('od.dod2.st').value.get()
|
||||
cfg.option('od.dod0.st').value.set('val')
|
||||
assert cfg.option('od.dod0.st').value.get() == 'val'
|
||||
assert cfg.option('od.dod1.st').value.get() is None
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('od.dod2.st').value.get()
|
||||
|
||||
|
||||
def test_makedict_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
|
|
|
|||
|
|
@ -165,15 +165,15 @@ def test_force_store_value():
|
|||
cfg = Config(od1)
|
||||
compare(cfg.value.exportation(), {})
|
||||
cfg.property.read_write()
|
||||
compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}})
|
||||
compare(cfg.value.exportation(), {'wantref3': {None: [[False], 'forced']}})
|
||||
cfg.option('bool').value.set(False)
|
||||
cfg.option('wantref').value.set(True)
|
||||
cfg.option('bool').value.reset()
|
||||
compare(cfg.value.exportation(), {'wantref': {None: [True, 'user']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}})
|
||||
compare(cfg.value.exportation(), {'wantref': {None: [True, 'user']}, 'wantref3': {None: [[False], 'forced']}})
|
||||
cfg.option('bool').value.set(False)
|
||||
cfg.option('wantref').value.reset()
|
||||
cfg.option('bool').value.reset()
|
||||
compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}})
|
||||
compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}})
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -932,6 +932,45 @@ def test_none_is_not_modified():
|
|||
# assert not list_sessions()
|
||||
|
||||
|
||||
def test_force_store_value_disabled_value():
|
||||
gcdummy = StrOption('dummy', 'dummy', properties=('force_store_value',))
|
||||
gcdummy1 = StrOption('dummy1', 'dummy1', default="str", properties=('force_store_value', 'disabled'))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy, gcdummy1])
|
||||
od1 = OptionDescription('tiramisu', '', [gcgroup])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
assert cfg.value.exportation() == {}
|
||||
cfg.option('gc.dummy1').permissive.add('disabled')
|
||||
assert cfg.option('gc.dummy1').value.get() == 'str'
|
||||
# do not export
|
||||
assert cfg._config_bag.context.get_values()._values == {None: {None: [None, 'user']},'gc.dummy1': {None: ['str', 'forced']}}
|
||||
|
||||
|
||||
def test_force_store_value_disabled_owner():
|
||||
gcdummy = StrOption('dummy', 'dummy', properties=('force_store_value',))
|
||||
gcdummy1 = StrOption('dummy1', 'dummy1', default="str", properties=('force_store_value', 'disabled'))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy, gcdummy1])
|
||||
od1 = OptionDescription('tiramisu', '', [gcgroup])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
assert cfg.value.exportation() == {}
|
||||
cfg.option('gc.dummy1').permissive.add('disabled')
|
||||
assert cfg.option('gc.dummy1').owner.get() == owners.forced
|
||||
assert cfg.value.exportation() == {'gc.dummy1': {None: ['str', 'forced']}}
|
||||
|
||||
|
||||
def test_force_store_value_disabled_exportation():
|
||||
gcdummy = StrOption('dummy', 'dummy', properties=('force_store_value',))
|
||||
gcdummy1 = StrOption('dummy1', 'dummy1', default="str", properties=('force_store_value', 'disabled'))
|
||||
gcgroup = OptionDescription('gc', '', [gcdummy, gcdummy1])
|
||||
od1 = OptionDescription('tiramisu', '', [gcgroup])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
assert cfg.value.exportation() == {}
|
||||
cfg.option('gc.dummy1').permissive.add('disabled')
|
||||
assert cfg.value.exportation() == {'gc.dummy1': {None: ['str', 'forced']}}
|
||||
|
||||
|
||||
def test_pprint():
|
||||
msg_error = _("cannot access to {0} {1} because has {2} {3}")
|
||||
msg_is_not = _('the value of "{0}" is not {1}')
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import pytest
|
|||
|
||||
from tiramisu import BoolOption, StrOption, IPOption, NetmaskOption, NetworkOption, BroadcastOption, \
|
||||
IntOption, OptionDescription, Leadership, Config, Params, ParamValue, ParamOption, \
|
||||
ParamSelfOption, ParamIndex, ParamInformation, ParamSelfInformation, ParamSelfOption, Calculation, \
|
||||
ParamSelfOption, ParamIndex, ParamInformation, ParamSelfInformation, Calculation, \
|
||||
valid_ip_netmask, valid_network_netmask, \
|
||||
valid_in_network, valid_broadcast, valid_not_equal
|
||||
from tiramisu.setting import groups
|
||||
|
|
|
|||
|
|
@ -583,6 +583,7 @@ class _TiramisuOptionOptionDescription:
|
|||
convert: bool = False,
|
||||
):
|
||||
"""Get identifiers for dynamic option"""
|
||||
subconfig = self._subconfig
|
||||
if not only_self:
|
||||
if self._subconfig.is_dynamic_without_identifiers and not uncalculated:
|
||||
raise AttributeOptionError(self._subconfig.path, "option-dynamic")
|
||||
|
|
@ -590,7 +591,6 @@ class _TiramisuOptionOptionDescription:
|
|||
return self._subconfig.identifiers
|
||||
identifiers = []
|
||||
dynconfig = None
|
||||
subconfig = self._subconfig
|
||||
while not dynconfig:
|
||||
if subconfig.option.impl_is_optiondescription() and subconfig.option.impl_is_dynoptiondescription():
|
||||
dynconfig = subconfig
|
||||
|
|
@ -607,7 +607,8 @@ class _TiramisuOptionOptionDescription:
|
|||
raise ConfigError(
|
||||
_(
|
||||
"the option {0} is not a dynamic option, cannot get identifiers with only_self parameter to True"
|
||||
).format(self._subconfig.path)
|
||||
).format(self._subconfig.path),
|
||||
subconfig=subconfig,
|
||||
)
|
||||
return self._subconfig.option.get_identifiers(
|
||||
self._subconfig.parent,
|
||||
|
|
@ -1454,6 +1455,7 @@ class TiramisuContextValue(TiramisuConfig, _TiramisuODGet):
|
|||
with_default_owner: bool = False,
|
||||
):
|
||||
"""Export all values"""
|
||||
self._force_store_value()
|
||||
exportation = deepcopy(self._config_bag.context.get_values()._values)
|
||||
if not with_default_owner:
|
||||
del exportation[None]
|
||||
|
|
@ -1469,6 +1471,10 @@ class TiramisuContextValue(TiramisuConfig, _TiramisuODGet):
|
|||
if None not in values:
|
||||
cvalues._values[None] = {None: [None, current_owner]}
|
||||
|
||||
def _force_store_value(self):
|
||||
descr = self._config_bag.context.get_description()
|
||||
descr.impl_build_force_store_values(self._config_bag)
|
||||
|
||||
|
||||
class TiramisuContextOwner(TiramisuConfig):
|
||||
"""Global owner"""
|
||||
|
|
|
|||
|
|
@ -172,15 +172,17 @@ class ParamDynOption(ParamOption):
|
|||
|
||||
|
||||
class ParamSelfOption(Param):
|
||||
__slots__ = "whole"
|
||||
__slots__ = ("whole", "dynamic")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
whole: bool = undefined,
|
||||
dynamic: bool = True,
|
||||
) -> None:
|
||||
"""whole: send all value for a multi, not only indexed value"""
|
||||
if whole is not undefined:
|
||||
self.whole = whole
|
||||
self.dynamic = dynamic
|
||||
|
||||
|
||||
class ParamValue(Param):
|
||||
|
|
@ -460,7 +462,7 @@ def manager_callback(
|
|||
or param.raisepropertyerror
|
||||
):
|
||||
raise err from err
|
||||
raise ConfigError(err)
|
||||
raise ConfigError(err, subconfig=subconfig)
|
||||
except ValueError as err:
|
||||
display_name = subconfig.option.impl_get_display_name(
|
||||
subconfig, with_quote=True
|
||||
|
|
@ -613,6 +615,33 @@ def manager_callback(
|
|||
return subconfig.identifiers[param.identifier_index]
|
||||
|
||||
if isinstance(param, ParamSelfOption):
|
||||
search_option = subconfig.option
|
||||
if subconfig.option.issubdyn() and not param.dynamic:
|
||||
subconfigs = subconfig.parent.parent.get_common_child(
|
||||
search_option,
|
||||
true_path=subconfig.path,
|
||||
validate_properties=False,
|
||||
)
|
||||
values = []
|
||||
properties = config_bag.context.get_settings().getproperties(
|
||||
subconfig,
|
||||
uncalculated=True,
|
||||
) - {'validator', 'mandatory', 'empty'}
|
||||
for subconfig_ in subconfigs:
|
||||
if subconfig.path == subconfig_.path:
|
||||
values.append(orig_value)
|
||||
else:
|
||||
subconfig_.properties = properties
|
||||
values.append(get_value(
|
||||
config_bag,
|
||||
subconfig_,
|
||||
param,
|
||||
True,
|
||||
))
|
||||
if callback.__name__ not in FUNCTION_WAITING_FOR_DICT:
|
||||
return values
|
||||
return {"name": search_option.impl_get_display_name(subconfig), "value": values}
|
||||
else:
|
||||
value = calc_self(
|
||||
param,
|
||||
index,
|
||||
|
|
@ -762,7 +791,9 @@ def manager_callback(
|
|||
]
|
||||
values = None
|
||||
for subconfig in subconfigs:
|
||||
callbk_option = subconfig.option
|
||||
if isinstance(subconfig, PropertiesOptionError):
|
||||
value = subconfig
|
||||
else:
|
||||
value = get_value(
|
||||
config_bag,
|
||||
subconfig,
|
||||
|
|
@ -777,6 +808,8 @@ def manager_callback(
|
|||
value = values
|
||||
if callback.__name__ not in FUNCTION_WAITING_FOR_DICT:
|
||||
return value
|
||||
# FIXME the last one?
|
||||
callbk_option = subconfig.option
|
||||
return {"name": callbk_option.impl_get_display_name(subconfig), "value": value}
|
||||
|
||||
|
||||
|
|
@ -925,6 +958,7 @@ def calculate(
|
|||
raise err from err
|
||||
error = err
|
||||
except ConfigError as err:
|
||||
err.subconfig = subconfig
|
||||
raise err from err
|
||||
except Exception as err:
|
||||
error = err
|
||||
|
|
|
|||
|
|
@ -42,8 +42,14 @@ from . import autolib
|
|||
|
||||
|
||||
def get_common_path(path1, path2):
|
||||
if None in (path1, path2):
|
||||
return None
|
||||
common_path = commonprefix([path1, path2])
|
||||
if common_path in [path1, path2]:
|
||||
all_paths = [path1, path2]
|
||||
if common_path in all_paths:
|
||||
# od.st is not the common_path of od.st_in
|
||||
all_paths.remove(common_path)
|
||||
if all_paths[0].startswith(common_path + '.'):
|
||||
return common_path
|
||||
if common_path.endswith("."):
|
||||
return common_path[:-1]
|
||||
|
|
@ -88,23 +94,30 @@ class CCache:
|
|||
subconfig,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
*,
|
||||
force=False,
|
||||
):
|
||||
"""reset cache for one option"""
|
||||
if subconfig.path in resetted_opts:
|
||||
if not force and subconfig.path in resetted_opts:
|
||||
return
|
||||
resetted_opts.append(subconfig.path)
|
||||
config_bag = subconfig.config_bag
|
||||
if not force:
|
||||
# if is_default and config_bag.context.get_owner(subconfig) != owners.default:
|
||||
# return
|
||||
for is_default, woption in subconfig.option.get_dependencies(subconfig.option):
|
||||
option = woption()
|
||||
if option.issubdyn():
|
||||
# it's an option in dynoptiondescription, remove cache for all generated option
|
||||
if option.impl_getpath() == subconfig.option.impl_getpath():
|
||||
force = True
|
||||
subconfig = subconfig.parent.parent
|
||||
self.reset_cache_dyn_option(
|
||||
subconfig,
|
||||
option,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
force,
|
||||
)
|
||||
elif option.impl_is_dynoptiondescription():
|
||||
self.reset_cache_dyn_optiondescription(
|
||||
|
|
@ -182,6 +195,10 @@ class CCache:
|
|||
def get_dynamic_from_dyn_option(self, subconfig, option):
|
||||
config_bag = subconfig.config_bag
|
||||
sub_paths = option.impl_getpath()
|
||||
if not subconfig.path:
|
||||
current_paths = []
|
||||
current_paths_max_index = 0
|
||||
else:
|
||||
current_paths = subconfig.path.split(".")
|
||||
current_paths_max_index = len(current_paths) - 1
|
||||
current_subconfigs = []
|
||||
|
|
@ -189,7 +206,7 @@ class CCache:
|
|||
while True:
|
||||
current_subconfigs.insert(0, parent)
|
||||
parent = parent.parent
|
||||
if parent.path is None:
|
||||
if not parent or parent.path is None:
|
||||
break
|
||||
currents = [self.get_root(config_bag)]
|
||||
for idx, sub_path in enumerate(sub_paths.split(".")):
|
||||
|
|
@ -234,12 +251,14 @@ class CCache:
|
|||
option,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
force,
|
||||
):
|
||||
for dyn_option_subconfig in self.get_dynamic_from_dyn_option(subconfig, option):
|
||||
self.reset_one_option_cache(
|
||||
dyn_option_subconfig,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
force=force,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -503,7 +522,7 @@ class SubConfig:
|
|||
)
|
||||
if check_index and index is not None:
|
||||
if option.impl_is_optiondescription() or not option.impl_is_follower():
|
||||
raise ConfigError("index must be set only with a follower option")
|
||||
raise ConfigError("index must be set only with a follower option", subconfig=subsubconfig,)
|
||||
length = self.get_length_leadership()
|
||||
if index >= length:
|
||||
raise LeadershipError(
|
||||
|
|
@ -569,10 +588,17 @@ class SubConfig:
|
|||
parents = [self.parent]
|
||||
else:
|
||||
if common_path:
|
||||
parent = self.parent
|
||||
common_parent_number = common_path.count(".") + 1
|
||||
for idx in range(current_option_path.count(".") - common_parent_number):
|
||||
parent_count = current_option_path.count(".") - common_parent_number
|
||||
if parent_count >= 0:
|
||||
parent = self.parent
|
||||
for idx in range(parent_count):
|
||||
parent = parent.parent
|
||||
elif parent_count == 0:
|
||||
parent = self.parent
|
||||
else:
|
||||
# so -1
|
||||
parent = self
|
||||
parents = [parent]
|
||||
else:
|
||||
common_parent_number = 0
|
||||
|
|
@ -617,14 +643,16 @@ class SubConfig:
|
|||
parents = new_parents
|
||||
subconfigs = []
|
||||
for parent in parents:
|
||||
subconfigs.append(
|
||||
parent.get_child(
|
||||
try:
|
||||
ret = parent.get_child(
|
||||
search_option,
|
||||
index,
|
||||
validate_properties,
|
||||
check_dynamic_without_identifiers=check_dynamic_without_identifiers,
|
||||
)
|
||||
)
|
||||
except PropertiesOptionError as err:
|
||||
ret = err
|
||||
subconfigs.append(ret)
|
||||
if subconfigs_is_a_list:
|
||||
return subconfigs
|
||||
return subconfigs[0]
|
||||
|
|
@ -1398,7 +1426,7 @@ class KernelGroupConfig(_CommonConfig):
|
|||
# pylint: disable=protected-access
|
||||
ret.append(
|
||||
PropertiesOptionError(
|
||||
err._subconfig,
|
||||
err.subconfig,
|
||||
err.proptype,
|
||||
err._settings,
|
||||
err._opt_type,
|
||||
|
|
@ -1646,7 +1674,7 @@ class KernelMixConfig(KernelGroupConfig):
|
|||
# pylint: disable=protected-access
|
||||
ret.append(
|
||||
PropertiesOptionError(
|
||||
err._subconfig,
|
||||
err.subconfig,
|
||||
err.proptype,
|
||||
err._settings,
|
||||
err._opt_type,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
import weakref
|
||||
from .i18n import _
|
||||
|
||||
from typing import Literal, Union
|
||||
from typing import Literal, Union, Optional
|
||||
|
||||
|
||||
TiramisuErrorCode = Literal[
|
||||
|
|
@ -101,7 +101,7 @@ class PropertiesOptionError(AttributeError):
|
|||
subconfig, with_quote=True
|
||||
)
|
||||
self._orig_opt = None
|
||||
self._subconfig = subconfig
|
||||
self.subconfig = subconfig
|
||||
self.proptype = proptype
|
||||
self.help_properties = help_properties
|
||||
self._settings = settings
|
||||
|
|
@ -136,7 +136,7 @@ class PropertiesOptionError(AttributeError):
|
|||
self._orig_opt.impl_get_display_name(subconfig, with_quote=True)
|
||||
)
|
||||
arguments.append(self._name)
|
||||
index = self._subconfig.index
|
||||
index = self.subconfig.index
|
||||
if index is not None:
|
||||
arguments.append(index)
|
||||
if self.code == "property-frozen":
|
||||
|
|
@ -215,10 +215,22 @@ class ConfigError(Exception):
|
|||
def __init__(
|
||||
self,
|
||||
exp,
|
||||
ori_err=None,
|
||||
*,
|
||||
prefix: Optional[str] = None,
|
||||
subconfig: Optional["Subconfig"]=None,
|
||||
):
|
||||
super().__init__(exp)
|
||||
self.ori_err = ori_err
|
||||
self.err_msg = exp
|
||||
self.subconfig = subconfig
|
||||
self.prefix = prefix
|
||||
|
||||
def __str__(self):
|
||||
msg = self.prefix
|
||||
if msg:
|
||||
msg += ", {}".format(self.err_msg)
|
||||
else:
|
||||
msg = self.err_msg
|
||||
return msg
|
||||
|
||||
|
||||
class ConflictError(Exception):
|
||||
|
|
@ -419,9 +431,9 @@ class Errors:
|
|||
display_name = option.impl_get_display_name(subconfig, with_quote=True)
|
||||
if original_error:
|
||||
raise ConfigError(
|
||||
message.format(display_name, original_error, *extra_keys)
|
||||
message.format(display_name, original_error, *extra_keys), subconfig=subconfig,
|
||||
) from original_error
|
||||
raise ConfigError(message.format(display_name, extra_keys))
|
||||
raise ConfigError(message.format(display_name, extra_keys), subconfig=subconfig)
|
||||
|
||||
|
||||
errors = Errors()
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ from itertools import chain
|
|||
|
||||
from ..i18n import _
|
||||
from ..setting import undefined
|
||||
from ..autolib import Calculation, ParamOption, ParamInformation, ParamSelfInformation
|
||||
from ..autolib import Calculation, ParamOption, ParamSelfOption, ParamInformation, ParamSelfInformation
|
||||
|
||||
STATIC_TUPLE = frozenset()
|
||||
|
||||
|
|
@ -104,9 +104,7 @@ class Base:
|
|||
"Calculation"
|
||||
).format(type(prop), name)
|
||||
)
|
||||
for param in chain(prop.params.args, prop.params.kwargs.values()):
|
||||
if isinstance(param, ParamOption):
|
||||
param.option._add_dependency(self, "property")
|
||||
self.value_dependency(prop, type_="property")
|
||||
if properties:
|
||||
_setattr(self, "_properties", properties)
|
||||
self.set_informations(informations)
|
||||
|
|
@ -395,16 +393,22 @@ class BaseOption(Base):
|
|||
self,
|
||||
value: Any,
|
||||
is_identifier: bool = False,
|
||||
type_: str = 'default'
|
||||
) -> Any:
|
||||
if not isinstance(is_identifier, bool):
|
||||
raise Exception()
|
||||
"""parse dependancy to add dependencies"""
|
||||
for param in chain(value.params.args, value.params.kwargs.values()):
|
||||
if isinstance(param, ParamOption):
|
||||
# pylint: disable=protected-access
|
||||
if is_identifier:
|
||||
type_ = "identifier"
|
||||
_type_ = "identifier"
|
||||
else:
|
||||
type_ = "default"
|
||||
param.option._add_dependency(self, type_, is_identifier=is_identifier)
|
||||
_type_ = type_
|
||||
param.option._add_dependency(self, _type_, is_identifier=is_identifier)
|
||||
self._has_dependency = True
|
||||
elif isinstance(param, ParamSelfOption) and not param.dynamic:
|
||||
self._add_dependency(self, "self")
|
||||
self._has_dependency = True
|
||||
elif isinstance(param, ParamInformation):
|
||||
dest = self
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@ class ChoiceOption(Option):
|
|||
:param values: is a list of values the option can possibly take
|
||||
"""
|
||||
if isinstance(values, Calculation):
|
||||
for param in chain(values.params.args, values.params.kwargs.values()):
|
||||
if isinstance(param, ParamOption):
|
||||
param.option._add_dependency(self, "choice")
|
||||
self.value_dependency(values, type_="choice")
|
||||
elif not isinstance(values, tuple):
|
||||
raise TypeError(
|
||||
_("values must be a tuple or a calculation for {0}").format(name)
|
||||
|
|
@ -75,7 +73,8 @@ class ChoiceOption(Option):
|
|||
raise ConfigError(
|
||||
_('the calculated values "{0}" for "{1}" is not a list' "").format(
|
||||
values, self.impl_getname()
|
||||
)
|
||||
),
|
||||
subconfig=subconfig,
|
||||
)
|
||||
return values
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ from ..i18n import _
|
|||
from .optiondescription import OptionDescription
|
||||
from .baseoption import BaseOption
|
||||
from ..setting import ConfigBag, undefined
|
||||
from ..error import ConfigError
|
||||
from ..autolib import Calculation, get_calculated_value
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class IntOption(Option):
|
|||
value: int,
|
||||
) -> None:
|
||||
if not isinstance(value, int):
|
||||
raise ValueError(_("which is not an integer"))
|
||||
raise ValueError(_("it's not an integer"))
|
||||
|
||||
def second_level_validation(self, value, warnings_only):
|
||||
min_integer = self.impl_get_extra("min_integer")
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ from ..setting import ConfigBag, groups, undefined, owners, Undefined
|
|||
from .baseoption import BaseOption
|
||||
|
||||
# from .syndynoption import SubDynOptionDescription, SynDynOptionDescription
|
||||
from ..error import ConfigError, ConflictError, AttributeOptionError
|
||||
from ..error import ConfigError, ConflictError, AttributeOptionError, PropertiesOptionError
|
||||
|
||||
|
||||
class CacheOptionDescription(BaseOption):
|
||||
|
|
@ -164,6 +164,7 @@ class CacheOptionDescription(BaseOption):
|
|||
parent,
|
||||
allow_dynoption=True,
|
||||
)
|
||||
try:
|
||||
if doption.impl_is_dynoptiondescription():
|
||||
new_parents.extend(
|
||||
parent.dyn_to_subconfig(
|
||||
|
|
@ -176,22 +177,26 @@ class CacheOptionDescription(BaseOption):
|
|||
parent.get_child(
|
||||
doption,
|
||||
None,
|
||||
True,
|
||||
name=name,
|
||||
validate_properties=True,
|
||||
)
|
||||
)
|
||||
except PropertiesOptionError:
|
||||
continue
|
||||
parents = new_parents
|
||||
subconfigs = new_parents
|
||||
else:
|
||||
try:
|
||||
subconfigs = [
|
||||
context.get_sub_config(
|
||||
config_bag,
|
||||
option.impl_getpath(),
|
||||
None,
|
||||
properties=None,
|
||||
validate_properties=False,
|
||||
validate_properties=True,
|
||||
)
|
||||
]
|
||||
except PropertiesOptionError:
|
||||
continue
|
||||
|
||||
if option.impl_is_follower():
|
||||
for follower_subconfig in subconfigs:
|
||||
|
|
@ -206,32 +211,14 @@ class CacheOptionDescription(BaseOption):
|
|||
idx_follower_subconfig = parent.get_child(
|
||||
follower_subconfig.option,
|
||||
index,
|
||||
validate_properties=False,
|
||||
)
|
||||
|
||||
value = values.get_value(idx_follower_subconfig)[0]
|
||||
if value is None:
|
||||
continue
|
||||
values.set_storage_value(
|
||||
follower_subconfig.path,
|
||||
index,
|
||||
value,
|
||||
owners.forced,
|
||||
validate_properties=True,
|
||||
)
|
||||
values.set_force_store_value(idx_follower_subconfig)
|
||||
else:
|
||||
for subconfig in subconfigs:
|
||||
subconfig.properties = frozenset()
|
||||
value = values.get_value(subconfig)[0]
|
||||
if value is None:
|
||||
continue
|
||||
if values.hasvalue(subconfig.path):
|
||||
continue
|
||||
values.set_storage_value(
|
||||
subconfig.path,
|
||||
None,
|
||||
value,
|
||||
owners.forced,
|
||||
)
|
||||
values.set_force_store_value(subconfig)
|
||||
|
||||
|
||||
class OptionDescriptionWalk(CacheOptionDescription):
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class StrOption(Option):
|
|||
) -> None:
|
||||
"""validation"""
|
||||
if not isinstance(value, str):
|
||||
raise ValueError(_("which is not a string"))
|
||||
raise ValueError(_("it's not a string"))
|
||||
|
||||
|
||||
class RegexpOption(StrOption):
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
"""
|
||||
from typing import Any, Optional, Dict
|
||||
from .baseoption import BaseOption, valid_name
|
||||
from ..error import ConfigError
|
||||
from ..i18n import _
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -638,7 +638,8 @@ class Settings:
|
|||
raise ConfigError(
|
||||
_("cannot add those permissives: {0}").format(
|
||||
" ".join(forbidden_permissives)
|
||||
)
|
||||
),
|
||||
subconfig=subconfig,
|
||||
)
|
||||
self._permissives.setdefault(path, {})[index] = permissives
|
||||
if subconfig is not None:
|
||||
|
|
|
|||
|
|
@ -110,22 +110,52 @@ class Values:
|
|||
value, owner = self._values.get(subconfig.path, {}).get(
|
||||
subconfig.index, default_value
|
||||
)
|
||||
if owner == owners.default or (
|
||||
"frozen" in subconfig.properties
|
||||
self_properties = subconfig.properties or tuple()
|
||||
if owner != owners.default and (
|
||||
"frozen" in self_properties
|
||||
and (
|
||||
"force_default_on_freeze" in subconfig.properties
|
||||
"force_default_on_freeze" in self_properties
|
||||
or self.check_force_to_metaconfig(subconfig)
|
||||
)
|
||||
):
|
||||
# the value is a default value
|
||||
# get it
|
||||
value = self.get_default_value(subconfig)
|
||||
if owner == owners.default:
|
||||
if(
|
||||
"force_store_value" in subconfig.config_bag.properties
|
||||
and "force_store_value" in self_properties
|
||||
):
|
||||
value = self.get_default_value(subconfig)
|
||||
if value is not None:
|
||||
owner = owners.forced
|
||||
self._setvalue(
|
||||
subconfig,
|
||||
value,
|
||||
owner,
|
||||
)
|
||||
else:
|
||||
# the value is a default value
|
||||
# get it
|
||||
value = self.get_default_value(subconfig)
|
||||
value, has_calculation = get_calculated_value(
|
||||
subconfig,
|
||||
value,
|
||||
)
|
||||
return value, has_calculation
|
||||
|
||||
def set_force_store_value(self, subconfig):
|
||||
value = self.get_default_value(subconfig)
|
||||
if value is None:
|
||||
return None
|
||||
owner = owners.forced
|
||||
self._setvalue(
|
||||
subconfig,
|
||||
value,
|
||||
owner,
|
||||
)
|
||||
return value, owner
|
||||
|
||||
def get_default_owner(
|
||||
self,
|
||||
subconfig: "SubConfig",
|
||||
|
|
@ -523,12 +553,18 @@ class Values:
|
|||
was present
|
||||
:returns: a `setting.owners.Owner` object
|
||||
"""
|
||||
s_properties = subconfig.properties
|
||||
self_properties = subconfig.properties
|
||||
if (
|
||||
"frozen" in s_properties
|
||||
and "force_default_on_freeze" in s_properties
|
||||
"frozen" in self_properties
|
||||
and "force_default_on_freeze" in self_properties
|
||||
):
|
||||
return owners.default
|
||||
setting_properties = subconfig.config_bag.properties
|
||||
if (
|
||||
"force_store_value" in setting_properties
|
||||
and "force_store_value" in self_properties
|
||||
):
|
||||
self.set_force_store_value(subconfig)
|
||||
if only_default:
|
||||
if self.hasvalue(
|
||||
subconfig.path,
|
||||
|
|
@ -544,8 +580,8 @@ class Values:
|
|||
)[1]
|
||||
if validate_meta is not False and (
|
||||
owner is owners.default
|
||||
or "frozen" in s_properties
|
||||
and "force_metaconfig_on_freeze" in s_properties
|
||||
or "frozen" in self_properties
|
||||
and "force_metaconfig_on_freeze" in self_properties
|
||||
):
|
||||
msubconfig = self._get_modified_parent(subconfig)
|
||||
if msubconfig is not None:
|
||||
|
|
@ -554,7 +590,7 @@ class Values:
|
|||
msubconfig,
|
||||
only_default=only_default,
|
||||
)
|
||||
elif "force_metaconfig_on_freeze" in s_properties:
|
||||
elif "force_metaconfig_on_freeze" in self_properties:
|
||||
owner = owners.default
|
||||
return owner
|
||||
|
||||
|
|
@ -579,7 +615,8 @@ class Values:
|
|||
raise ConfigError(
|
||||
_(
|
||||
'"{0}" is a default value, so we cannot change owner to "{1}"'
|
||||
).format(subconfig.path, owner)
|
||||
).format(subconfig.path, owner),
|
||||
subconfig=subconfig,
|
||||
)
|
||||
subconfig.config_bag.context.get_settings().validate_frozen(subconfig)
|
||||
self._values[subconfig.path][subconfig.index][1] = owner
|
||||
|
|
@ -630,13 +667,7 @@ class Values:
|
|||
"force_store_value" in setting_properties
|
||||
and "force_store_value" in self_properties
|
||||
):
|
||||
value = self.get_default_value(subconfig)
|
||||
|
||||
self._setvalue(
|
||||
subconfig,
|
||||
value,
|
||||
owners.forced,
|
||||
)
|
||||
self.set_force_store_value(subconfig)
|
||||
else:
|
||||
value = None
|
||||
if subconfig.path in self._values:
|
||||
|
|
@ -702,15 +733,9 @@ class Values:
|
|||
"force_store_value" in setting_properties
|
||||
and "force_store_value" in self_properties
|
||||
):
|
||||
value = self.get_default_value(
|
||||
subconfig,
|
||||
)
|
||||
|
||||
self._setvalue(
|
||||
subconfig,
|
||||
value,
|
||||
owners.forced,
|
||||
)
|
||||
force_store_value = self.set_force_store_value(subconfig)
|
||||
if force_store_value:
|
||||
value, owner = force_store_value
|
||||
else:
|
||||
self.resetvalue_index(subconfig)
|
||||
context.reset_cache(subconfig)
|
||||
|
|
|
|||
Loading…
Reference in a new issue