diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 15b4c2a..71a076b 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -586,41 +586,49 @@ class Settings(object): # validate properties def validate_properties(self, - opt_or_descr, + opt, path, setting_properties, index=None, force_permissive=False): """ - validation upon the properties related to `opt_or_descr` + validation upon the properties related to `opt` - :param opt_or_descr: an option or an option description object + :param opt: an option or an option description object :param force_permissive: behaves as if the permissive property was present """ # opt properties - properties = self.getproperties(opt_or_descr, - path, - setting_properties=setting_properties, - index=index) + self_properties = self.getproperties(opt, + path, + setting_properties=setting_properties, + index=index) + # calc properties - properties &= setting_properties - set(['frozen']) - if not opt_or_descr.impl_is_optiondescription(): + properties = self_properties & setting_properties - set(['frozen']) + if not opt.impl_is_optiondescription(): #mandatory if 'mandatory' in properties or 'empty' in properties: - value = 'pouet' - if self.validate_mandatory(opt_or_descr, - index, - value, - setting_properties, - properties): - properties += set(['mandatory']) - set(['empty']) + value = self._getcontext().cfgimpl_get_values().get_cached_value(opt, + path=path, + validate=False, + setting_properties=setting_properties, + self_properties=self_properties, + index=index) + if not self.validate_mandatory(opt, + index, + value, + setting_properties, + properties): + properties -= set(['mandatory']) else: - properties -= set(['mandatory', 'empty']) + properties |= set(['mandatory']) + properties -= set(['empty']) opt_type = 'option' else: opt_type = 'optiondescription' + # remove permissive properties if force_permissive is True and properties: # remove global permissive if need @@ -628,7 +636,7 @@ class Settings(object): # at this point an option should not remain in properties if properties != frozenset(): - datas = {'opt': opt_or_descr, + datas = {'opt': opt, 'path': path, 'setting_properties': setting_properties, 'index': index, diff --git a/tiramisu/value.py b/tiramisu/value.py index 07ce96b..02ee9d6 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -70,16 +70,7 @@ class Values(object): self_properties=undefined, index=None, display_warnings=True): - context = self._getcontext() - settings = context.cfgimpl_get_settings() - if path is None: - path = opt.impl_getpath(context) ntime = None - if self_properties is undefined: - self_properties = settings.getproperties(opt, - path, - setting_properties=setting_properties, - index=index) if 'cache' in setting_properties and self._p_.hascache(path, index): if 'expire' in setting_properties: ntime = int(time()) @@ -113,7 +104,7 @@ class Values(object): path, validate, setting_properties, - self_properties=None, + self_properties=undefined, index=None, display_warnings=True, force_permissive=False): @@ -181,6 +172,12 @@ class Values(object): :param opt: the `option.Option()` object :returns: the option's value (or the default value if not set) """ + if self_properties is undefined: + settings = self._getcontext().cfgimpl_get_settings() + self_properties = settings.getproperties(opt, + path, + setting_properties=setting_properties, + index=index) force_default = 'frozen' in self_properties and \ 'force_default_on_freeze' in self_properties # not default value @@ -243,9 +240,13 @@ class Values(object): context.cfgimpl_reset_cache(opt=opt, path=path) + if opt.impl_is_master_slaves('slave'): + index_ = index + else: + index_ = None if self._is_meta(opt, path, - index, + index_, setting_properties, force_permissive=force_permissive): meta = context.cfgimpl_get_meta() @@ -344,10 +345,7 @@ class Values(object): else: allow_empty_list = opt.impl_allow_empty_list() if allow_empty_list is undefined: - if opt.impl_is_master_slaves('slave'): - allow_empty_list = True - else: - allow_empty_list = False + allow_empty_list = opt.impl_is_master_slaves('slave') isempty = value is None or (not allow_empty_list and value == []) or \ None in value or empty in value else: @@ -744,7 +742,8 @@ class Values(object): #______________________________________________________________________ # mandatory warnings - def mandatory_warnings(self, force_permissive=True): + def mandatory_warnings(self, + force_permissive=True): """convenience function to trace Options that are mandatory and where no value has been set @@ -776,10 +775,14 @@ class Values(object): if opt.impl_is_optiondescription(): #FIXME ? - if not settings.validate_properties(opt, True, False, path=path, + if not settings.validate_properties(opt, + True, + False, + path=path, force_permissive=True, setting_properties=setting_properties): - for path in _mandatory_warnings(opt, currpath + [name]): + for path in _mandatory_warnings(opt, + currpath + [name]): yield path else: if opt.impl_is_symlinkoption(): @@ -788,7 +791,8 @@ class Values(object): path, setting_properties=setting_properties) if 'mandatory' in self_properties or 'empty' in self_properties: - err = self.get_cached_value(opt, path=path, + err = self.get_cached_value(opt, + path=path, trusted_cached_properties=False, force_permissive=True, setting_properties=setting_properties,