Compare commits

..

No commits in common. "aaf832c12d22dea5be5f56c7d5036ddd12966018" and "3177d11f13fc791779363b6dfc569f73cf3a9e24" have entirely different histories.

5 changed files with 26 additions and 101 deletions

View file

@ -244,6 +244,9 @@ class Annotator(Walk):
leader: "self.objectspace.variable",
follower: "self.objectspace.variable",
) -> None:
if follower.auto_save is True:
msg = _(f'leader/followers "{follower.name}" could not be auto_save')
raise DictConsistencyError(msg, 29, follower.xmlfiles)
if leader == follower:
# it's a leader
if not leader.mode:

View file

@ -216,16 +216,19 @@ extra_dictionaries:
description: Extra namespaces
type: leadership
disabled:
variable: main_namespace
when: null
type: jinja
jinja: |
{% if not main_namespace %}
main_namespace not available
{% endif %}
names:
description: 'Extra namespace name'
alternative_name: xn
alternative_name: x
multi: true
mandatory: false
directories:
description: Directories where extra dictionary files are placed
alternative_name: xd
alternative_name: d
type: unix_filename
params:
allow_relative: true
@ -235,7 +238,7 @@ extra_dictionaries:
multi: true
functions_files:
description: File with functions
alternative_name: c
alternative_name: f
type: unix_filename
params:
allow_relative: true

View file

@ -590,18 +590,7 @@ class ParserVariable:
extra_attrs = set(family_obj) - self.family_attrs
if extra_attrs:
raise Exception(f"extra attrs ... {extra_attrs}")
obj_type = self.get_family_or_variable_type(family_obj)
if obj_type is None:
# auto set type
if '_dynamic' in family_obj:
dynamic = family_obj['_dynamic']
elif 'dynamic' in family_obj:
dynamic = family_obj['dynamic']
else:
dynamic = None
if isinstance(dynamic, (list, dict)):
family_obj['type'] = obj_type = 'dynamic'
if obj_type == "dynamic":
if self.get_family_or_variable_type(family_obj) == "dynamic":
family_is_dynamic = True
parent_dynamic = path
if '{{ suffix }}' not in name:
@ -1010,16 +999,11 @@ class ParserVariable:
calculations = calculations[0]
else:
calculations = calculations[1]
if not isinstance(value, dict) or attribute not in calculations:
return False
if 'type' in value:
return value['type'] in CALCULATION_TYPES
# auto set type
typ = set(CALCULATION_TYPES) & set(value)
if len(typ) == 1:
value['type'] = list(typ)[0]
return True
return False
return (
attribute in calculations
and isinstance(value, dict)
and value.get("type") in CALCULATION_TYPES
)
def set_calculation(
self,
@ -1052,11 +1036,6 @@ class ParserVariable:
raise Exception("params must be a dict")
params = []
for key, val in calculation_object["params"].items():
if isinstance(val, dict) and "type" not in val:
# auto set type
param_typ = set(CALCULATION_TYPES) & set(val)
if len(param_typ) == 1:
val['type'] = list(param_typ)[0]
if not isinstance(val, dict) or "type" not in val:
param_typ = "any"
val = {
@ -1235,8 +1214,6 @@ class RougailConvert(ParserVariable):
objects,
filename,
)
if objects is None:
return
self.parse_root_file(filename,
path,
version,
@ -1291,8 +1268,6 @@ class RougailConvert(ParserVariable):
filename: str,
) -> None:
"""version is mandatory in YAML file"""
if obj is None:
obj = {}
for name in ["_version", "version"]:
if name not in obj:
continue

View file

@ -102,7 +102,6 @@ CONVERT_OPTION = {
example="644",
),
"choice": dict(opttype="ChoiceOption", example="a_choice"),
"regexp": dict(opttype="RegexpOption"),
#
"symlink": dict(opttype="SymLinkOption"),
}
@ -589,61 +588,20 @@ class InformationCalculation(Calculation):
}
class _SuffixCalculation(Calculation):
class SuffixCalculation(Calculation):
attribute_name: Literal["default", "choice", "dynamic"]
suffix: Optional[int] = None
def get_suffix(self) -> dict:
def to_function(
self,
objectspace,
) -> dict:
suffix = {"type": "suffix"}
if self.suffix is not None:
suffix["suffix"] = self.suffix
return suffix
class SuffixCalculation(_SuffixCalculation):
attribute_name: Literal["default", "choice", "dynamic"]
def to_function(
self,
objectspace,
) -> dict:
return {
"function": "calc_value",
"params": {None: [self.get_suffix()]},
}
class SuffixPropertyCalculation(_SuffixCalculation):
attribute_name: Literal[*PROPERTY_ATTRIBUTE]
when: Any = undefined
when_not: Any = undefined
def to_function(
self,
objectspace,
) -> dict:
if self.version == "1.0":
msg = f'when is not allowed in format version 1.0 for attribute "{self.attribute_name}"'
raise DictConsistencyError(msg, 105, variable.xmlfiles)
if self.when is not undefined:
if self.when_not is not undefined:
msg = f'the suffix has an invalid attribute "{self.attribute_name}", when and when_not cannot set together'
raise DictConsistencyError(msg, 35, variable.xmlfiles)
when = self.when
inverse = False
elif self.when_not is not undefined:
when = self.when_not
inverse = True
else:
msg = f'the suffix has an invalid attribute "{self.attribute_name}", when and when_not cannot set together'
raise DictConsistencyError
params = {None: [self.attribute_name, self.get_suffix()],
"when": when,
"inverse": inverse,
}
return {
"function": "variable_to_property",
"params": params,
"help": "variable_to_property",
"params": {None: [suffix]},
}
@ -674,7 +632,7 @@ CALCULATION_PROPERTY_TYPES = {
"jinja": JinjaCalculation,
"variable": VariablePropertyCalculation,
"information": InformationCalculation,
"suffix": SuffixPropertyCalculation,
"suffix": SuffixCalculation,
"index": IndexCalculation,
}
BASETYPE_CALC = Union[StrictBool, StrictInt, StrictFloat, StrictStr, Calculation, None]
@ -709,7 +667,6 @@ class Variable(BaseModel):
description: Optional[str] = None
default: Union[List[BASETYPE_CALC], BASETYPE_CALC] = None
choices: Optional[Union[List[BASETYPE_CALC], Calculation]] = None
regexp: Optional[str] = None
params: Optional[List[Param]] = None
validators: Optional[List[Calculation]] = None
multi: Optional[bool] = None
@ -721,7 +678,6 @@ class Variable(BaseModel):
auto_save: bool = False
mode: Optional[str] = None
test: Optional[list] = None
examples: Optional[list] = None
path: str
namespace: Optional[str]
version: str

View file

@ -30,7 +30,6 @@ class Annotator(Walk):
def __init__(self, objectspace, *args) -> None:
if not objectspace.paths:
return
self.alternative_names = {}
self.objectspace = objectspace
not_for_commandlines = []
for family in self.get_families():
@ -60,17 +59,6 @@ class Annotator(Walk):
return
alternative_name = variable.alternative_name
variable_path = variable.path
all_letters = ''
for letter in alternative_name:
all_letters += letter
if all_letters == 'h':
msg = _(f'alternative_name "{alternative_name}" conflict with "--help"')
raise DictConsistencyError(msg, 202, variable.xmlfiles)
if all_letters in self.alternative_names:
msg = _(f'conflict alternative_name "{alternative_name}": "{variable_path}" and "{self.alternative_names[all_letters]}"')
raise DictConsistencyError(msg, 202, variable.xmlfiles)
self.alternative_names[alternative_name] = variable_path
if '.' not in variable_path:
path = alternative_name
else:
@ -83,7 +71,7 @@ class Annotator(Walk):
raise DictConsistencyError(_(f'negative_description is mandatory for boolean variable, but "{variable.path}" hasn\'t'), 200, variable.xmlfiles)
return
if variable.type != 'boolean':
raise DictConsistencyError(_(f'negative_description is only available for boolean variable, but "{variable.path}" is "{variable.type}"'), 201, variable.xmlfiles)
raise DictConsistencyError(_(f'negative_description is only available for boolean variable, but "{variable.path}" is "{variable.type}"'), 200, variable.xmlfiles)
self.objectspace.informations.add(
variable.path, "negative_description", variable.negative_description
)