object in constrainte

This commit is contained in:
Emmanuel Garette 2021-01-16 20:10:13 +01:00
parent e34d285eb3
commit 82e8057e9d
3 changed files with 11 additions and 16 deletions

View File

@ -141,14 +141,7 @@ class ConstrainteAnnotator:
param_option_indexes.append(idx) param_option_indexes.append(idx)
else: else:
# let's replace params by the path # let's replace params by the path
param.text, suffix = self.objectspace.paths.get_variable_path(param.text, param.text = self.objectspace.paths.get_variable_obj(param.text)
check.namespace,
)
if suffix:
xmlfiles = self.objectspace.display_xmlfiles(param.xmlfiles)
msg = _(f'the param "{param.text}" in check cannot be a dynamic '
f'variable in {xmlfiles}')
raise DictConsistencyError(msg, 23)
param_option_indexes.sort(reverse=True) param_option_indexes.sort(reverse=True)
for idx in param_option_indexes: for idx in param_option_indexes:
check.param.pop(idx) check.param.pop(idx)
@ -223,7 +216,7 @@ class ConstrainteAnnotator:
msg = _(f'optional parameter in valid_enum for variable "{variable.name}" ' msg = _(f'optional parameter in valid_enum for variable "{variable.name}" '
f'is not allowed in {xmlfiles}') f'is not allowed in {xmlfiles}')
raise DictConsistencyError(msg, 14) raise DictConsistencyError(msg, 14)
param_variable = self.objectspace.paths.get_variable_obj(param.text) param_variable = param.text
if not param_variable.multi: if not param_variable.multi:
xmlfiles = self.objectspace.display_xmlfiles(param.xmlfiles) xmlfiles = self.objectspace.display_xmlfiles(param.xmlfiles)
msg = _(f'only multi "variable" parameter is allowed for valid_enum ' msg = _(f'only multi "variable" parameter is allowed for valid_enum '
@ -608,10 +601,10 @@ class ConstrainteAnnotator:
raise DictConsistencyError(msg, 27) raise DictConsistencyError(msg, 27)
if param.type == 'variable': if param.type == 'variable':
try: try:
text, suffix = self.objectspace.paths.get_variable_path(param.text, path, suffix = self.objectspace.paths.get_variable_path(param.text,
fill.namespace, fill.namespace,
) )
param.text = text param.text = self.objectspace.paths.get_variable_obj(path)
if suffix: if suffix:
param.suffix = suffix param.suffix = suffix
except DictConsistencyError as err: except DictConsistencyError as err:

View File

@ -25,6 +25,8 @@ class Path:
full_name = '.'.join([namespace, name]) full_name = '.'.join([namespace, name])
self.full_paths_families[name] = full_name self.full_paths_families[name] = full_name
else: else:
if '.' not in name:
raise DictConsistencyError(_(f'Variable "{name}" in namespace "{namespace}" must have dot'), 39)
full_name = name full_name = name
if full_name in self.families and \ if full_name in self.families and \
self.families[full_name]['variableobj'] != variableobj: # pragma: no cover self.families[full_name]['variableobj'] != variableobj: # pragma: no cover
@ -140,13 +142,13 @@ class Path:
def get_variable_path(self, def get_variable_path(self,
name: str, name: str,
current_namespace: str, current_namespace: str,
allow_source: str=False, allow_variable_namespace: str=False,
) -> str: # pylint: disable=C0111 ) -> str: # pylint: disable=C0111
dico, suffix = self._get_variable(name, dico, suffix = self._get_variable(name,
with_suffix=True, with_suffix=True,
) )
namespace = dico['variableobj'].namespace namespace = dico['variableobj'].namespace
if not allow_source and namespace not in [Config['variable_namespace'], 'services'] and current_namespace != namespace: if not allow_variable_namespace and namespace not in [Config['variable_namespace'], 'services'] and current_namespace != namespace:
raise DictConsistencyError(_(f'A variable located in the "{namespace}" namespace shall not be used in the "{current_namespace}" namespace'), 41) raise DictConsistencyError(_(f'A variable located in the "{namespace}" namespace shall not be used in the "{current_namespace}" namespace'), 41)
return dico['variableobj'].path, suffix return dico['variableobj'].path, suffix

View File

@ -324,7 +324,7 @@ class Variable(Common):
self.attrib['validators'].append(self.calculation_value(child, ['ParamSelfOption()'])) self.attrib['validators'].append(self.calculation_value(child, ['ParamSelfOption()']))
elif tag == 'choice': elif tag == 'choice':
if child.type == 'calculation': if child.type == 'calculation':
value = self.storage.get(child.name).get() value = self.storage.get(child.name.path).get()
choices = f"Calculation(func.calc_value, Params((ParamOption({value}))))" choices = f"Calculation(func.calc_value, Params((ParamOption({value}))))"
else: else:
choices.append(child.name) choices.append(child.name)
@ -400,9 +400,9 @@ class Variable(Common):
def build_param(self, def build_param(self,
param, param,
): ):
option_name = self.storage.get(param['option']).get() option_name = self.storage.get(param['option'].path).get()
if 'suffix' in param: if 'suffix' in param:
family = '.'.join(param['option'].split('.')[:-1]) family = '.'.join(param['option'].path.split('.')[:-1])
family_option = self.storage.get_name(family) family_option = self.storage.get_name(family)
return f"ParamDynOption({option_name}, '{param['suffix']}', {family_option}, notraisepropertyerror={param['notraisepropertyerror']}, todict={param['todict']})" return f"ParamDynOption({option_name}, '{param['suffix']}', {family_option}, notraisepropertyerror={param['notraisepropertyerror']}, todict={param['todict']})"
return f"ParamOption({option_name}, notraisepropertyerror={param['notraisepropertyerror']}, todict={param['todict']})" return f"ParamOption({option_name}, notraisepropertyerror={param['notraisepropertyerror']}, todict={param['todict']})"