From 71ec5b71488ea6c3ed40f1cce0958771cdd7bae6 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 1 Sep 2018 06:59:20 +0200 Subject: [PATCH] split validate_properties and calc raises properties --- tiramisu/setting.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 5951c73..4112419 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -124,7 +124,7 @@ class OptionBag: 'config_bag', 'ori_option', # original option (for example useful for symlinkoption) 'properties', # properties of current option - 'apply_requires', + 'apply_requires', # apply requires or not for this option 'fromconsistency' # history for consistency ) @@ -147,7 +147,8 @@ class OptionBag: def __getattr__(self, key): if key == 'properties': settings = self.config_bag.context.cfgimpl_get_settings() - self.properties = settings.getproperties(self, apply_requires=self.apply_requires) + self.properties = settings.getproperties(self, + apply_requires=self.apply_requires) return self.properties elif key == 'ori_option': return self.option @@ -189,6 +190,11 @@ class ConfigBag: def set_permissive(self): self.properties = frozenset(self.properties | {'permissive'}) + def __delattr__(self, key): + if key == 'properties': + return + raise KeyError('unknown key {} for ConfigBag'.format(key)) + def copy(self): kwargs = {} for key in self.__slots__: @@ -689,6 +695,16 @@ class Settings(object): #____________________________________________________________ # validate properties + def calc_raises_properties(self, + option_properties, + config_properties, + config_permissives): + properties = option_properties & config_properties - {'frozen', 'mandatory', 'empty'} + # remove global permissive properties + if properties and ('permissive' in config_properties): + properties -= config_permissives + # at this point an option should not remain in properties + return properties def validate_properties(self, option_bag): @@ -702,14 +718,9 @@ class Settings(object): config_bag = option_bag.config_bag if not config_bag.properties: return - # calc properties - properties = option_bag.properties & config_bag.properties - {'frozen', 'mandatory', 'empty'} - - # remove permissive properties - if properties and ('permissive' in config_bag.properties): - # remove global permissive if need - properties -= config_bag.permissives - # at this point an option should not remain in properties + properties = self.calc_raises_properties(option_bag.properties, + option_bag.config_bag.properties, + option_bag.config_bag.permissives) if properties != frozenset(): raise PropertiesOptionError(option_bag, properties,