From b381e0322f4ac1b47965bd190ef0050884f617e3 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 18 Aug 2018 08:06:29 +0200 Subject: [PATCH] force_permissive +> permissive --- tiramisu/api.py | 24 ++++++------- tiramisu/autolib.py | 2 +- tiramisu/option/option.py | 4 +-- tiramisu/setting.py | 49 ++++++++++++++------------ tiramisu/storage/dictionary/setting.py | 4 +-- tiramisu/value.py | 2 +- 6 files changed, 43 insertions(+), 42 deletions(-) diff --git a/tiramisu/api.py b/tiramisu/api.py index 3dac7a6..4baff11 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -362,8 +362,8 @@ class TiramisuOptionPermissive(CommonTiramisuOption): def get(self): """get permissives value""" - option = self.option_bag.option - return self.settings.getpermissive(option, self.option_bag.path) + return self.settings.getpermissives(self.option_bag.option, + self.option_bag.path) def set(self, permissives): """set permissives value""" @@ -979,22 +979,22 @@ class TiramisuAPI(TiramisuHelp): else: config = self._config force = None - config_bag = ConfigBag(context=config, - force_permissive=True) + config_bag = ConfigBag(context=config) + config_bag.set_permissive() if force is True: config_bag.properties = frozenset() return TiramisuAPI(config_bag) elif subfunc == 'unrestraint': - if isinstance(self._config, ConfigBag): - config = self._config.context - force = self._config.force_permissive - else: - config = self._config - force = None + #if isinstance(self._config, ConfigBag): + # config = self._config.context + # force = self._config.force_permissive + #else: + config = self._config + #force = None config_bag = ConfigBag(context=config) config_bag.properties = frozenset() - if force is not None: - config_bag.force_permissive = force + #if force is not None: + #config_bag.force_permissive = force return TiramisuAPI(config_bag) elif subfunc in self.registers: if not isinstance(self._config, ConfigBag): diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index adbcb4e..fdff42a 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -74,7 +74,7 @@ def manager_callback(callbk: Union[ParamOption, ParamValue], return orig_value # don't validate if option is option that we tried to validate config_bag = option_bag.config_bag.copy() - config_bag.force_permissive = True + config_bag.set_permissive() soption_bag = OptionBag() soption_bag.set_option(opt, path, diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 812fd3f..0b45b22 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -467,11 +467,9 @@ class Option(OnlyOption): if consistencies: if option_bag.config_bag is undefined: cconfig_bag = undefined - elif option_bag.config_bag.force_permissive != True: - cconfig_bag = option_bag.config_bag.copy() - cconfig_bag.force_permissive = True else: cconfig_bag = option_bag.config_bag + cconfig_bag.set_permissive() for cons_id, func, all_cons_opts, params in consistencies: warnings_only = params.get('warnings_only', False) if (warnings_only and not check_error) or (not warnings_only and check_error): diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 1cd33b4..ee2346b 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -161,12 +161,12 @@ class OptionBag: class ConfigBag: __slots__ = ('context', # link to the current context 'properties', # properties for current context - #'permissives', # permissives for current context - 'force_permissive', # force permissive + 'permissives', # permissives for current context + #'force_permissive', # force permissive '_validate', # validate ) def __init__(self, context, **kwargs): - self.force_permissive = False + #self.force_permissive = False self.context = context self._validate = True for key, value in kwargs.items(): @@ -176,6 +176,9 @@ class ConfigBag: if key == 'properties': self.properties = self.context.cfgimpl_get_settings().get_context_properties() return self.properties + if key == 'permissives': + self.permissives = self.context.cfgimpl_get_settings().get_context_permissives() + return self.permissives raise KeyError('unknown key {} for ConfigBag'.format(key)) def remove_validation(self): @@ -187,6 +190,9 @@ class ConfigBag: if self._validate: self.properties = frozenset(self.properties | {'validator'}) + def set_permissive(self): + self.properties = frozenset(self.properties | {'permissive'}) + def copy(self): kwargs = {} for key in self.__slots__: @@ -393,8 +399,8 @@ class Settings(object): if apply_requires: props |= self.apply_requires(option_bag, False) - props -= self.getpermissive(opt, - path) + props -= self.getpermissives(opt, + path) if apply_requires: self._p_.setcache(path, index, @@ -404,20 +410,20 @@ class Settings(object): config_bag.properties) return props - def get_context_permissive(self): - return self.getpermissive(None, None) + def get_context_permissives(self): + return self.getpermissives(None, None) - def getpermissive(self, - opt, - path): + def getpermissives(self, + opt, + path): 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().getpermissive(opt, - path) - return self._pp_.getpermissive(path) + return meta.cfgimpl_get_settings().getpermissives(opt, + path) + return self._pp_.getpermissives(path) def apply_requires(self, option_bag, @@ -497,7 +503,7 @@ class Settings(object): elif option.impl_is_multi(): is_indexed = True config_bag = option_bag.config_bag.copy() - config_bag.force_permissive = True + config_bag.set_permissive() soption_bag = OptionBag() soption_bag.set_option(option, reqpath, @@ -703,10 +709,9 @@ class Settings(object): properties = option_bag.properties & config_bag.properties - {'frozen', 'mandatory', 'empty'} # remove permissive properties - if (config_bag.force_permissive is True or \ - 'permissive' in config_bag.properties) and properties: + if properties and ('permissive' in config_bag.properties): # remove global permissive if need - properties -= self.get_context_permissive() + properties -= config_bag.permissives # at this point an option should not remain in properties if properties != frozenset(): raise PropertiesOptionError(option_bag, @@ -719,9 +724,8 @@ class Settings(object): if 'mandatory' in option_bag.config_bag.properties: values = self._getcontext().cfgimpl_get_values() is_mandatory = False - if (option_bag.config_bag.force_permissive is True or \ - 'permissive' in option_bag.config_bag.properties) and \ - 'mandatory' in self.get_context_permissive(): + if ('permissive' in option_bag.config_bag.properties) and \ + 'mandatory' in option_bag.config_bag.permissives: pass elif 'mandatory' in option_bag.properties and values.isempty(option_bag.option, value, @@ -742,9 +746,8 @@ class Settings(object): if option_bag.config_bag.properties and \ ('everything_frozen' in option_bag.config_bag.properties or 'frozen' in option_bag.properties) and \ - not ((option_bag.config_bag.force_permissive is True or - 'permissive' in option_bag.config_bag.properties) and - 'frozen' in self.get_context_permissive()): + not (('permissive' in option_bag.config_bag.properties) and + 'frozen' in option_bag.config_bag.permissives): raise PropertiesOptionError(option_bag, ['frozen'], self) diff --git a/tiramisu/storage/dictionary/setting.py b/tiramisu/storage/dictionary/setting.py index 317081f..c28ba33 100644 --- a/tiramisu/storage/dictionary/setting.py +++ b/tiramisu/storage/dictionary/setting.py @@ -82,10 +82,10 @@ class Permissives(Cache): else: self._permissives[path] = permissive - def getpermissive(self, path=None): + def getpermissives(self, path=None): ret = self._permissives.get(path, frozenset()) if DEBUG: # pragma: no cover - print('getpermissive', path, ret) + print('getpermissives', path, ret) return ret def exportation(self): diff --git a/tiramisu/value.py b/tiramisu/value.py index c439cc2..6bb3780 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -630,7 +630,7 @@ class Values(object): setting_properties.update(['mandatory', 'empty']) config_bag = ConfigBag(context=config_bag.context) config_bag.properties = frozenset(setting_properties) - config_bag.force_permissive = True + config_bag.set_permissive() descr = context.cfgimpl_get_description() return self._mandatory_warnings(context,