simplify meta support

This commit is contained in:
Emmanuel Garette 2018-09-05 22:46:45 +02:00
parent 7fa9b0637e
commit 1ef82af5d1
3 changed files with 16 additions and 50 deletions

View file

@ -295,7 +295,6 @@ def test_meta_unconsistent():
raises(ValueError, "MetaConfig([conf1, conf3])")
#not same descr
raises(ValueError, "MetaConfig([conf3, conf4])")
raises(ConfigError, "meta.config('conf1').property.read_only()")
def test_meta_master_slaves():

View file

@ -359,12 +359,8 @@ class Settings(object):
{},
'context_props')
if not is_cached:
meta = self._getcontext().cfgimpl_get_meta()
if meta is None:
props = self._p_.getproperties(None,
default_properties)
else:
props = meta.cfgimpl_get_settings().get_context_properties()
props = self._p_.getproperties(None,
default_properties)
self._p_.setcache(None,
None,
props,
@ -396,13 +392,8 @@ class Settings(object):
else:
is_cached = False
if not is_cached:
meta = self._getcontext().cfgimpl_get_meta()
if meta is None:
props = self._p_.getproperties(path,
opt.impl_getproperties())
else:
props = meta.cfgimpl_get_settings().getproperties(option_bag,
apply_requires)
props = self._p_.getproperties(path,
opt.impl_getproperties())
if apply_requires:
props |= self.apply_requires(option_bag,
False)
@ -425,10 +416,6 @@ class Settings(object):
if opt and opt.impl_is_symlinkoption():
opt = opt.impl_getopt()
path = opt.impl_getpath(self._getcontext())
meta = self._getcontext().cfgimpl_get_meta()
if meta is not None:
return meta.cfgimpl_get_settings().getpermissives(opt,
path)
return self._pp_.getpermissives(path)
def apply_requires(self,
@ -600,8 +587,6 @@ class Settings(object):
(never save properties if same has option properties)
"""
# should have index !!!
if self._getcontext().cfgimpl_get_meta() is not None:
raise ConfigError(_('cannot change property with metaconfig'))
if path is not None and option_bag.option.impl_getrequires() is not None:
not_allowed_props = properties & \
getattr(option_bag.option, '_calc_properties', static_set)
@ -650,8 +635,6 @@ class Settings(object):
it is better (faster) to set the path parameter
instead of passing a :class:`tiramisu.option.Option()` object.
"""
if self._getcontext().cfgimpl_get_meta() is not None:
raise ConfigError(_('cannot change permissive with metaconfig'))
if not isinstance(permissives, frozenset):
raise TypeError(_('permissive must be a frozenset'))
if option_bag is not None:
@ -676,8 +659,6 @@ class Settings(object):
def reset(self,
option_bag):
# all_properties=False):
if self._getcontext().cfgimpl_get_meta() is not None:
raise ConfigError(_('cannot change property with metaconfig'))
if option_bag is None:
opt = None
else:

View file

@ -191,18 +191,10 @@ class Values(object):
else:
moption_bag = option_bag
if self._is_meta(moption_bag):
moption_bag.properties = frozenset()
meta = context.cfgimpl_get_meta()
# retrieved value from meta config
try:
# FIXME could have different property!
value = meta.getattr(moption_bag.path,
moption_bag)
except PropertiesOptionError:
# if properties error, return an other default value
# unexpected error, should not happened
pass
else:
return value
return meta.cfgimpl_get_values().get_cached_value(moption_bag)
if opt.impl_has_callback():
# if value has callback, calculate value
@ -353,20 +345,13 @@ class Values(object):
commit)
def _is_meta(self,
option_bag,
force_owner_is_default=False):
if not force_owner_is_default and self._p_.hasvalue(option_bag.path,
index=option_bag.index):
# has already a value, so not meta
return False
option_bag):
context = self._getcontext()
meta = context.cfgimpl_get_meta()
if meta is None:
return False
opt = option_bag.option
if opt.impl_is_master_slaves('slave'):
master = opt.impl_get_master_slaves().getmaster()
if option_bag.option.impl_is_master_slaves('slave'):
master = option_bag.option.impl_get_master_slaves().getmaster()
masterp = master.impl_getpath(context)
# slave could be a "meta" only if master hasn't value
if self._p_.hasvalue(masterp,
@ -404,10 +389,10 @@ class Values(object):
opt = opt.impl_getopt()
option_bag.option = opt
option_bag.path = opt.impl_getpath(context)
self_properties = option_bag.properties
settings = context.cfgimpl_get_settings()
settings.validate_properties(option_bag)
if 'frozen' in self_properties and 'force_default_on_freeze' in self_properties:
if 'frozen' in option_bag.properties and \
'force_default_on_freeze' in option_bag.properties:
return owners.default
if only_default:
if self._p_.hasvalue(option_bag.path,
@ -419,11 +404,12 @@ class Values(object):
owner = self._p_.getowner(option_bag.path,
owners.default,
index=option_bag.index)
if owner is owners.default and validate_meta is not False:
if owner is owners.default and validate_meta is not False and self._is_meta(option_bag):
moption_bag = option_bag.copy()
moption_bag.properties = frozenset()
meta = context.cfgimpl_get_meta()
if meta is not None and self._is_meta(option_bag):
owner = meta.cfgimpl_get_values().getowner(option_bag,
only_default=only_default)
owner = meta.cfgimpl_get_values().getowner(moption_bag,
only_default=only_default)
return owner
def setowner(self,