force_permissive +> permissive
This commit is contained in:
parent
493cec1b80
commit
b381e0322f
|
@ -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:
|
||||
#if isinstance(self._config, ConfigBag):
|
||||
# config = self._config.context
|
||||
# force = self._config.force_permissive
|
||||
#else:
|
||||
config = self._config
|
||||
force = None
|
||||
#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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,7 +399,7 @@ class Settings(object):
|
|||
if apply_requires:
|
||||
props |= self.apply_requires(option_bag,
|
||||
False)
|
||||
props -= self.getpermissive(opt,
|
||||
props -= self.getpermissives(opt,
|
||||
path)
|
||||
if apply_requires:
|
||||
self._p_.setcache(path,
|
||||
|
@ -404,10 +410,10 @@ 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,
|
||||
def getpermissives(self,
|
||||
opt,
|
||||
path):
|
||||
if opt and opt.impl_is_symlinkoption():
|
||||
|
@ -415,9 +421,9 @@ class Settings(object):
|
|||
path = opt.impl_getpath(self._getcontext())
|
||||
meta = self._getcontext().cfgimpl_get_meta()
|
||||
if meta is not None:
|
||||
return meta.cfgimpl_get_settings().getpermissive(opt,
|
||||
return meta.cfgimpl_get_settings().getpermissives(opt,
|
||||
path)
|
||||
return self._pp_.getpermissive(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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue