diff --git a/src/rougail/annotator/__init__.py b/src/rougail/annotator/__init__.py index ef02d3fd..362fa485 100644 --- a/src/rougail/annotator/__init__.py +++ b/src/rougail/annotator/__init__.py @@ -25,9 +25,9 @@ class SpaceAnnotator: # pylint: disable=R0903 FillAnnotator(objectspace, eosfunc_file, ) + ValueAnnotator(objectspace) FamilyAnnotator(objectspace) PropertyAnnotator(objectspace) - ValueAnnotator(objectspace) __all__ = ('SpaceAnnotator', 'CONVERT_OPTION', 'modes') diff --git a/src/rougail/annotator/condition.py b/src/rougail/annotator/condition.py index bf244e96..94aeed33 100644 --- a/src/rougail/annotator/condition.py +++ b/src/rougail/annotator/condition.py @@ -196,7 +196,9 @@ class ConditionAnnotator: variable = self.objectspace.paths.get_family(target.name.path, target.namespace, ) - return variable, list(variable.variable.values()) + if hasattr(variable, 'variable'): + return variable, list(variable.variable.values()) + return variable, [] def convert_condition_source(self): """remove condition for ChoiceOption that don't have param diff --git a/src/rougail/annotator/family.py b/src/rougail/annotator/family.py index c0f8ea6e..d393cd8a 100644 --- a/src/rougail/annotator/family.py +++ b/src/rougail/annotator/family.py @@ -132,39 +132,13 @@ class FamilyAnnotator: family_mode: str, is_follower=False, ) -> None: - """if the variable is mandatory and doesn't have any value - then the variable's mode is set to 'basic' - """ - # a boolean must have value, the default value is "True" - if not hasattr(variable, 'value') and variable.type == 'boolean': - new_value = self.objectspace.value(variable.xmlfiles) - new_value.name = True - new_value.type = 'boolean' - variable.value = [new_value] - # variable with default value is mandatory - if hasattr(variable, 'value') and variable.value: - has_value = True - for value in variable.value: - if value.type == 'calculation': - has_value = False - break - if has_value: - # if has value without any calculation - variable.mandatory = True # mandatory variable without value is a basic variable - if variable.mandatory is True and (not hasattr(variable, 'value') or is_follower): + if variable.mandatory is True and not hasattr(variable, 'default'): variable.mode = modes_level[0] # none basic variable in high level family has to be in high level if modes[variable.mode] < modes[family_mode] and \ (not is_follower or variable.mode != modes_level[0]): variable.mode = family_mode - # hidden variable is also frozen - if variable.hidden is True: - variable.frozen = True - if not variable.auto_save and \ - not variable.auto_freeze and \ - 'force_default_on_freeze' not in vars(variable): - variable.force_default_on_freeze = True def change_family_mode(self): """change mode of a family diff --git a/src/rougail/annotator/property.py b/src/rougail/annotator/property.py index fd5bd844..ad528ec5 100644 --- a/src/rougail/annotator/property.py +++ b/src/rougail/annotator/property.py @@ -26,9 +26,15 @@ class PropertyAnnotator: ) -> None: """convert properties """ + # hidden variable is also frozen + if isinstance(variable, self.objectspace.variable) and variable.hidden is True: + variable.frozen = True + if not variable.auto_save and \ + not variable.auto_freeze and \ + 'force_default_on_freeze' not in vars(variable): + variable.force_default_on_freeze = True if not hasattr(variable, 'properties'): variable.properties = [] - for prop in PROPERTIES: if hasattr(variable, prop): if getattr(variable, prop) is True: diff --git a/src/rougail/annotator/value.py b/src/rougail/annotator/value.py index 06b414a3..400700a7 100644 --- a/src/rougail/annotator/value.py +++ b/src/rougail/annotator/value.py @@ -17,6 +17,8 @@ class ValueAnnotator: # pylint: disable=R0903 """ for families in self.objectspace.space.variables.values(): for family in families.family.values(): + if not hasattr(family, 'variable'): + continue for variable in family.variable.values(): if isinstance(variable, self.objectspace.leadership): variable_type = 'leader' @@ -28,10 +30,29 @@ class ValueAnnotator: # pylint: disable=R0903 else: self._convert_value(variable) - @staticmethod - def _convert_value(variable, + def _convert_value(self, + variable, variable_type: str=None, ) -> None: + # a boolean must have value, the default value is "True" + if not hasattr(variable, 'value') and variable.type == 'boolean': + new_value = self.objectspace.value(variable.xmlfiles) + new_value.name = True + new_value.type = 'boolean' + variable.value = [new_value] + """if the variable is mandatory and doesn't have any value + then the variable's mode is set to 'basic' + """ + # variable with default value is mandatory + if hasattr(variable, 'value') and variable.value: + has_value = True + for value in variable.value: + if value.type == 'calculation': + has_value = False + break + if has_value: + # if has value without any calculation + variable.mandatory = True if not hasattr(variable, 'value'): return if variable.value[0].type == 'calculation': diff --git a/src/rougail/tiramisureflector.py b/src/rougail/tiramisureflector.py index 1be95c48..8b4fe00c 100644 --- a/src/rougail/tiramisureflector.py +++ b/src/rougail/tiramisureflector.py @@ -240,7 +240,6 @@ class Variable(Common): if hasattr(self.elt, key) and getattr(self.elt, key) is not None: value = getattr(self.elt, key) if isinstance(value, str): - print('pouet') value = self.convert_str(value) elif isinstance(value, self.objectspace.value): value = self.calculation_value(value, []) diff --git a/tests/dictionaries/10load_hidden_if_empty_family/00-base.xml b/tests/dictionaries/10load_hidden_if_empty_family/00-base.xml new file mode 100644 index 00000000..4f82657d --- /dev/null +++ b/tests/dictionaries/10load_hidden_if_empty_family/00-base.xml @@ -0,0 +1,29 @@ + + + + + + non + + + non + + + non + + + + + + + + + oui + mode_conteneur_actif + mode_conteneur_actif2 + Général2 + + + + diff --git a/tests/dictionaries/10load_hidden_if_empty_family/__init__.py b/tests/dictionaries/10load_hidden_if_empty_family/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/10load_hidden_if_empty_family/makedict/base.json b/tests/dictionaries/10load_hidden_if_empty_family/makedict/base.json new file mode 100644 index 00000000..25db64a2 --- /dev/null +++ b/tests/dictionaries/10load_hidden_if_empty_family/makedict/base.json @@ -0,0 +1 @@ +{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non"} diff --git a/tests/dictionaries/10load_hidden_if_empty_family/tiramisu/__init__.py b/tests/dictionaries/10load_hidden_if_empty_family/tiramisu/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/10load_hidden_if_empty_family/tiramisu/base.py b/tests/dictionaries/10load_hidden_if_empty_family/tiramisu/base.py new file mode 100644 index 00000000..76c2af95 --- /dev/null +++ b/tests/dictionaries/10load_hidden_if_empty_family/tiramisu/base.py @@ -0,0 +1,20 @@ +from importlib.machinery import SourceFileLoader +from importlib.util import spec_from_loader, module_from_spec +loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') +spec = spec_from_loader(loader.name, loader) +func = module_from_spec(spec) +loader.exec_module(func) +for key, value in dict(locals()).items(): + if key != ['SourceFileLoader', 'func']: + setattr(func, key, value) +try: + from tiramisu3 import * +except: + from tiramisu import * +from rougail.tiramisu import ConvertDynOptionDescription +option_3 = StrOption(name="condition", doc="No change", default="non", properties=frozenset({"mandatory", "normal"})) +option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"mandatory", "normal", Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('force_default_on_freeze'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')}))})) +option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"mandatory", "normal", Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('force_default_on_freeze'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')}))})) +option_2 = OptionDescription(name="general", doc="Général", children=[option_3, option_4, option_5], properties=frozenset({"normal"})) +option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])