feat: value modified in parent config is a default value for current config and can get default owner for an option
This commit is contained in:
parent
43d3046e4c
commit
585cda5ffc
4 changed files with 41 additions and 9 deletions
|
|
@ -87,11 +87,14 @@ def test_none():
|
||||||
conf2 = meta.config('conf2')
|
conf2 = meta.config('conf2')
|
||||||
assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None
|
assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None
|
||||||
assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default
|
assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default
|
||||||
|
assert meta.option('od1.i3').owner.isdefault() and conf1.option('od1.i3').owner.isdefault()
|
||||||
#
|
#
|
||||||
#assert meta.option('od1.i3').value.set(3) == []
|
#assert meta.option('od1.i3').value.set(3) == []
|
||||||
meta.option('od1.i3').value.set(3)
|
meta.option('od1.i3').value.set(3)
|
||||||
assert meta.option('od1.i3').value.get() == conf1.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3
|
assert meta.option('od1.i3').value.get() == conf1.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3
|
||||||
assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1
|
assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1
|
||||||
|
assert not meta.option('od1.i3').owner.isdefault()
|
||||||
|
assert conf1.option('od1.i3').owner.isdefault()
|
||||||
#
|
#
|
||||||
conf1.option('od1.i3').value.set(2)
|
conf1.option('od1.i3').value.set(2)
|
||||||
assert meta.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3
|
assert meta.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3
|
||||||
|
|
@ -110,6 +113,8 @@ def test_none():
|
||||||
assert conf1.option('od1.i3').value.get() == 2
|
assert conf1.option('od1.i3').value.get() == 2
|
||||||
assert meta.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default
|
assert meta.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default
|
||||||
assert conf1.option('od1.i3').owner.get() is owners.user
|
assert conf1.option('od1.i3').owner.get() is owners.user
|
||||||
|
assert meta.option("od1.i3").owner.default() is owners.default
|
||||||
|
assert conf1.option("od1.i3").owner.default() is owners.default
|
||||||
#
|
#
|
||||||
conf1.option('od1.i3').value.reset()
|
conf1.option('od1.i3').value.reset()
|
||||||
assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None
|
assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None
|
||||||
|
|
|
||||||
|
|
@ -717,10 +717,27 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
||||||
self._subconfig, validate_meta=not only_self
|
self._subconfig, validate_meta=not only_self
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@option_type(["symlink", "option", "with_index"])
|
||||||
|
def default(self):
|
||||||
|
values = self._config_bag.context.get_values()
|
||||||
|
return values.get_default_owner(self._subconfig)
|
||||||
|
|
||||||
@option_type(["symlink", "option", "with_index"])
|
@option_type(["symlink", "option", "with_index"])
|
||||||
def isdefault(self):
|
def isdefault(self):
|
||||||
"""Is option has defaut value"""
|
"""Is option has defaut value"""
|
||||||
return self._config_bag.context.get_owner(self._subconfig) == owners.default
|
subconfig = self._subconfig
|
||||||
|
s_properties = subconfig.properties
|
||||||
|
if (
|
||||||
|
"frozen" in s_properties
|
||||||
|
and "force_default_on_freeze" in s_properties
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
context = self._config_bag.context
|
||||||
|
subconfig = context._get(
|
||||||
|
subconfig,
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
return not context.get_values().hasvalue(subconfig.path, index=subconfig.index)
|
||||||
|
|
||||||
@option_type(["option", "with_index"])
|
@option_type(["option", "with_index"])
|
||||||
def set(
|
def set(
|
||||||
|
|
@ -1775,7 +1792,7 @@ class TiramisuContextOption(TiramisuConfig, _TiramisuOptionWalk):
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
"""Get option path"""
|
"""Get option path"""
|
||||||
return None
|
return self._config_bag.context.get_config_path()
|
||||||
|
|
||||||
def has_dependency(
|
def has_dependency(
|
||||||
self,
|
self,
|
||||||
|
|
@ -1840,6 +1857,9 @@ class TiramisuContextOption(TiramisuConfig, _TiramisuOptionWalk):
|
||||||
self._load_dict()
|
self._load_dict()
|
||||||
return self._tiramisu_dict.set_updates(body)
|
return self._tiramisu_dict.set_updates(body)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'<{self.__class__.__name__} path="{self.path()}">'
|
||||||
|
|
||||||
|
|
||||||
class _TiramisuContextConfigReset:
|
class _TiramisuContextConfigReset:
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
|
@ -2075,9 +2095,7 @@ class TiramisuAPI(TiramisuHelp):
|
||||||
|
|
||||||
|
|
||||||
class ConfigProp(TiramisuAPI, TiramisuContextOption):
|
class ConfigProp(TiramisuAPI, TiramisuContextOption):
|
||||||
def __repr__(self):
|
pass
|
||||||
return f"<Config path=None>"
|
|
||||||
|
|
||||||
|
|
||||||
class Config(TiramisuAPI, TiramisuContextOption):
|
class Config(TiramisuAPI, TiramisuContextOption):
|
||||||
"""Root config object that enables us to handle the configuration options"""
|
"""Root config object that enables us to handle the configuration options"""
|
||||||
|
|
@ -2114,9 +2132,6 @@ class Config(TiramisuAPI, TiramisuContextOption):
|
||||||
except ConfigError:
|
except ConfigError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return f"<Config path=None>"
|
|
||||||
|
|
||||||
|
|
||||||
class MetaConfig(TiramisuAPI, TiramisuContextOption):
|
class MetaConfig(TiramisuAPI, TiramisuContextOption):
|
||||||
"""MetaConfig object that enables us to handle the sub configuration's options
|
"""MetaConfig object that enables us to handle the sub configuration's options
|
||||||
|
|
|
||||||
|
|
@ -1881,5 +1881,5 @@ class KernelMetaConfig(KernelMixConfig):
|
||||||
config,
|
config,
|
||||||
):
|
):
|
||||||
if self._impl_descr is not config.get_description():
|
if self._impl_descr is not config.get_description():
|
||||||
raise ValueError(_("metaconfig must " "have the same optiondescription"))
|
raise ValueError(_("metaconfig must have the same optiondescription"))
|
||||||
super().add_config(config)
|
super().add_config(config)
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,18 @@ class Values:
|
||||||
)
|
)
|
||||||
return value, has_calculation
|
return value, has_calculation
|
||||||
|
|
||||||
|
def get_default_owner(
|
||||||
|
self,
|
||||||
|
subconfig: "SubConfig",
|
||||||
|
) -> Any:
|
||||||
|
msubconfig = self._get_modified_parent(subconfig)
|
||||||
|
if msubconfig is not None:
|
||||||
|
# retrieved value from parent config
|
||||||
|
return msubconfig.config_bag.context.get_values().getowner(
|
||||||
|
msubconfig
|
||||||
|
)
|
||||||
|
return owners.default
|
||||||
|
|
||||||
def get_default_value(
|
def get_default_value(
|
||||||
self,
|
self,
|
||||||
subconfig: "SubConfig",
|
subconfig: "SubConfig",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue