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])") raises(ValueError, "MetaConfig([conf1, conf3])")
#not same descr #not same descr
raises(ValueError, "MetaConfig([conf3, conf4])") raises(ValueError, "MetaConfig([conf3, conf4])")
raises(ConfigError, "meta.config('conf1').property.read_only()")
def test_meta_master_slaves(): def test_meta_master_slaves():

View File

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

View File

@ -191,18 +191,10 @@ class Values(object):
else: else:
moption_bag = option_bag moption_bag = option_bag
if self._is_meta(moption_bag): if self._is_meta(moption_bag):
moption_bag.properties = frozenset()
meta = context.cfgimpl_get_meta() meta = context.cfgimpl_get_meta()
# retrieved value from meta config # retrieved value from meta config
try: return meta.cfgimpl_get_values().get_cached_value(moption_bag)
# 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
if opt.impl_has_callback(): if opt.impl_has_callback():
# if value has callback, calculate value # if value has callback, calculate value
@ -353,20 +345,13 @@ class Values(object):
commit) commit)
def _is_meta(self, def _is_meta(self,
option_bag, 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
context = self._getcontext() context = self._getcontext()
meta = context.cfgimpl_get_meta() meta = context.cfgimpl_get_meta()
if meta is None: if meta is None:
return False return False
opt = option_bag.option if option_bag.option.impl_is_master_slaves('slave'):
if opt.impl_is_master_slaves('slave'): master = option_bag.option.impl_get_master_slaves().getmaster()
master = opt.impl_get_master_slaves().getmaster()
masterp = master.impl_getpath(context) masterp = master.impl_getpath(context)
# slave could be a "meta" only if master hasn't value # slave could be a "meta" only if master hasn't value
if self._p_.hasvalue(masterp, if self._p_.hasvalue(masterp,
@ -404,10 +389,10 @@ class Values(object):
opt = opt.impl_getopt() opt = opt.impl_getopt()
option_bag.option = opt option_bag.option = opt
option_bag.path = opt.impl_getpath(context) option_bag.path = opt.impl_getpath(context)
self_properties = option_bag.properties
settings = context.cfgimpl_get_settings() settings = context.cfgimpl_get_settings()
settings.validate_properties(option_bag) 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 return owners.default
if only_default: if only_default:
if self._p_.hasvalue(option_bag.path, if self._p_.hasvalue(option_bag.path,
@ -419,11 +404,12 @@ class Values(object):
owner = self._p_.getowner(option_bag.path, owner = self._p_.getowner(option_bag.path,
owners.default, owners.default,
index=option_bag.index) 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() meta = context.cfgimpl_get_meta()
if meta is not None and self._is_meta(option_bag): owner = meta.cfgimpl_get_values().getowner(moption_bag,
owner = meta.cfgimpl_get_values().getowner(option_bag, only_default=only_default)
only_default=only_default)
return owner return owner
def setowner(self, def setowner(self,