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',
'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,