split validate_properties and calc raises properties

This commit is contained in:
Emmanuel Garette 2018-09-01 06:59:20 +02:00
parent c803298aa3
commit 71ec5b7148
1 changed files with 21 additions and 10 deletions

View File

@ -124,7 +124,7 @@ class OptionBag:
'config_bag', 'config_bag',
'ori_option', # original option (for example useful for symlinkoption) 'ori_option', # original option (for example useful for symlinkoption)
'properties', # properties of current option 'properties', # properties of current option
'apply_requires', 'apply_requires', # apply requires or not for this option
'fromconsistency' # history for consistency 'fromconsistency' # history for consistency
) )
@ -147,7 +147,8 @@ class OptionBag:
def __getattr__(self, key): def __getattr__(self, key):
if key == 'properties': if key == 'properties':
settings = self.config_bag.context.cfgimpl_get_settings() 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 return self.properties
elif key == 'ori_option': elif key == 'ori_option':
return self.option return self.option
@ -189,6 +190,11 @@ class ConfigBag:
def set_permissive(self): def set_permissive(self):
self.properties = frozenset(self.properties | {'permissive'}) 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): def copy(self):
kwargs = {} kwargs = {}
for key in self.__slots__: for key in self.__slots__:
@ -689,6 +695,16 @@ class Settings(object):
#____________________________________________________________ #____________________________________________________________
# validate properties # 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, def validate_properties(self,
option_bag): option_bag):
@ -702,14 +718,9 @@ class Settings(object):
config_bag = option_bag.config_bag config_bag = option_bag.config_bag
if not config_bag.properties: if not config_bag.properties:
return return
# calc properties properties = self.calc_raises_properties(option_bag.properties,
properties = option_bag.properties & config_bag.properties - {'frozen', 'mandatory', 'empty'} option_bag.config_bag.properties,
option_bag.config_bag.permissives)
# 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
if properties != frozenset(): if properties != frozenset():
raise PropertiesOptionError(option_bag, raise PropertiesOptionError(option_bag,
properties, properties,