From 34e0654bbe36f1689d5850d254453fba38da67fb Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 19 Jan 2026 16:18:38 +0100 Subject: [PATCH] fix: leadership and frozen --- src/rougail/annotator/property.py | 64 +++++++++++------- src/rougail/annotator/variable.py | 18 ++--- src/rougail/convert/object_model.py | 66 ++++++++----------- src/rougail/user_data.py | 33 +++++++--- src/rougail/utils.py | 1 - .../makedict/after.json | 1 + .../makedict/base.json | 1 + .../makedict/before.json | 1 + .../makedict/mandatory.json | 1 + .../makedict/read_write.json | 1 + .../tiramisu/base.py | 16 +++++ .../tiramisu/no_namespace.py | 15 +++++ .../tiramisu/base.py | 4 +- .../tiramisu/no_namespace.py | 4 +- tests/test_types.py | 5 -- tests/types/result/family/variables_rw.json | 3 + .../result/family_redefine/variables_rw.json | 8 +++ .../result/family_subfamily/variables_rw.json | 8 +++ tests/types/result/variable/variables_rw.json | 3 + .../types/result/variable_hidden/tiramisu.py | 22 +++++++ .../result/variable_hidden/variables.json | 7 ++ .../result/variable_hidden/variables_rw.json | 7 ++ .../types/result/variables/variables_rw.json | 5 ++ 23 files changed, 204 insertions(+), 90 deletions(-) create mode 100644 tests/dictionaries/04_5disabled_calculation_variable11/makedict/after.json create mode 100644 tests/dictionaries/04_5disabled_calculation_variable11/makedict/base.json create mode 100644 tests/dictionaries/04_5disabled_calculation_variable11/makedict/before.json create mode 100644 tests/dictionaries/04_5disabled_calculation_variable11/makedict/mandatory.json create mode 100644 tests/dictionaries/04_5disabled_calculation_variable11/makedict/read_write.json create mode 100644 tests/dictionaries/04_5disabled_calculation_variable11/tiramisu/base.py create mode 100644 tests/dictionaries/04_5disabled_calculation_variable11/tiramisu/no_namespace.py create mode 100644 tests/types/result/family/variables_rw.json create mode 100644 tests/types/result/family_redefine/variables_rw.json create mode 100644 tests/types/result/family_subfamily/variables_rw.json create mode 100644 tests/types/result/variable/variables_rw.json create mode 100644 tests/types/result/variable_hidden/tiramisu.py create mode 100644 tests/types/result/variable_hidden/variables.json create mode 100644 tests/types/result/variable_hidden/variables_rw.json create mode 100644 tests/types/result/variables/variables_rw.json diff --git a/src/rougail/annotator/property.py b/src/rougail/annotator/property.py index 7297b688b..a6d87bbd2 100644 --- a/src/rougail/annotator/property.py +++ b/src/rougail/annotator/property.py @@ -53,31 +53,52 @@ class Annotator(Walk): self.objectspace = objectspace self.frozen = {} if self.objectspace.paths: + self.convert_leadership() self.convert_family() self.convert_variable() + def convert_leadership(self) -> None: + for variable_path in self.objectspace.leaders: + variable = self.objectspace.paths[variable_path] + if variable.hidden: + family = self.objectspace.paths[variable.path.rsplit(".", 1)[0]] + hidden = variable.hidden + if hidden is not True: + hidden = hidden.model_copy() + if hidden.ori_path is None: + hidden.ori_path = variable_path + family.hidden = hidden + variable.hidden = None + def convert_family(self) -> None: """convert families""" for family in self.get_families(): self._convert_property(family) # collect for force_default_on_freeze if family.hidden: + if family.hidden is True: + frozen = True + else: + frozen = family.hidden.model_copy() + frozen.attribute_name = "frozen" + if frozen.ori_path is None: + frozen.ori_path = family.path self.set_variable_frozen( family.path, - family.hidden, + frozen, ) def set_variable_frozen( self, family_path: str, - hidden: Union[bool, Calculation], + frozen: Union[bool, Calculation], ) -> None: for variable_path in self.objectspace.parents[family_path]: if variable_path in self.objectspace.families: # it's a family self.set_variable_frozen( variable_path, - hidden, + frozen, ) else: # it's a variable @@ -86,13 +107,16 @@ class Annotator(Walk): if ( self.frozen.get(variable.path) is True or variable.hidden is True - or hidden is True + or frozen is True ): self.frozen[variable.path] = True - elif variable.path in self.frozen: - self.frozen[variable.path].append(hidden) else: - self.frozen[variable.path] = [hidden] + if variable.path in self.frozen: + if not isinstance(self.frozen[variable.path], list): + self.frozen[variable.path] = [frozen] + self.frozen[variable.path].append(frozen) + else: + self.frozen[variable.path] = frozen def convert_variable(self) -> None: """convert variables""" @@ -114,22 +138,18 @@ class Annotator(Walk): if variable.hidden is True: self.frozen[path] = True elif self.frozen.get(path) is not True: - self.frozen.setdefault(path, []).append(variable.hidden) + frozen = variable.hidden.model_copy() + frozen.attribute_name = "frozen" + if frozen.ori_path is None: + frozen.ori_path = path + if path in self.frozen: + if not isinstance(self.frozen, list): + self.frozen[path] = [self.frozen[path]] + self.frozen[path].append(frozen) + else: + self.frozen[path] = frozen if path in self.frozen: - frozen = self.frozen[path] - if frozen is True: - value = True - else: - value = [] - for calculation in frozen: - calculation_copy = calculation.model_copy() - calculation_copy.attribute_name = "frozen" -# calculation_copy.ori_path = calculation_copy.path -# calculation_copy.path = path - value.append(calculation_copy) - if len(value) == 1: - value = value[0] - self.objectspace.properties.add(path, "frozen", value) + self.objectspace.properties.add(path, "frozen", self.frozen[path]) if not variable.auto_save: # if auto_save, save calculated value self.objectspace.properties.add(path, "force_default_on_freeze", True) diff --git a/src/rougail/annotator/variable.py b/src/rougail/annotator/variable.py index b341a5d82..4aed75cd9 100644 --- a/src/rougail/annotator/variable.py +++ b/src/rougail/annotator/variable.py @@ -51,8 +51,6 @@ class Walk: for path in self.objectspace.variables: yield self.objectspace.paths[path] - # yield from get_variables(self.objectspace) - def get_families(self): """Iter all families from the objectspace""" for path in self.objectspace.families: @@ -178,7 +176,6 @@ class Annotator(Walk): # pylint: disable=R0903 variable.validators.append( JinjaCalculation( - path=variable.path, inside_list=True, version=variable.version, xmlfiles=variable.xmlfiles, @@ -242,7 +239,7 @@ class Annotator(Walk): # pylint: disable=R0903 if calculated_variable.multi is None: if ( isinstance(calculated_variable.default, VariableCalculation) - and variable.path == calculated_variable.default.variable + and variable.path == calculated_variable.path ): msg = _( 'the "{0}" default value is a calculation with itself' @@ -276,6 +273,12 @@ class Annotator(Walk): # pylint: disable=R0903 variable.params = calculated_variable.params if variable.type == "choice" and variable.choices is None: variable.choices = calculated_variable.choices + if isinstance(variable.choices, VariableCalculation): + variable.choices = variable.choices.model_copy() + variable.choices.variable = self.objectspace.paths.get_full_path( + variable.choices.variable, + calculated_variable.path, + ) if variable.type == "regexp" and variable.regexp is None: variable.regexp = calculated_variable.regexp @@ -297,13 +300,6 @@ class Annotator(Walk): # pylint: disable=R0903 self.objectspace.multis[variable.path] = "submulti" elif variable.multi: self.objectspace.multis[variable.path] = True - if variable.path in self.objectspace.leaders: - family = self.objectspace.paths[variable.path.rsplit(".", 1)[0]] - if variable.hidden: - family.hidden = variable.hidden - # elif family.hidden: - # variable.hidden = family.hidden - variable.hidden = None if variable.regexp is not None and variable.type != "regexp": msg = _( 'the variable "{0}" has regexp attribut but has not the "regexp" type' diff --git a/src/rougail/convert/object_model.py b/src/rougail/convert/object_model.py index f1fc9ed27..52c19caf5 100644 --- a/src/rougail/convert/object_model.py +++ b/src/rougail/convert/object_model.py @@ -250,7 +250,7 @@ class Calculation(BaseModel): # path: str inside_list: bool version: str - # ori_path: Optional[str] = None + ori_path: Optional[str] = None default_values: Any = None namespace: Optional[str] warnings: Optional[bool] = None @@ -261,15 +261,11 @@ class Calculation(BaseModel): def get_params(self, objectspace, path): if self.warnings is not None and self.attribute_name != "validators": msg = _( - '"warnings" are only available with attribute "{self.attribute_name}" for variable "{self.ori_path}"' + '"warnings" are only available with attribute "{self.attribute_name}" for variable "{self.path}"' ) raise DictConsistencyError(msg, 83, xmlfiles) if not self.params: return {} -# if self.ori_path is None: -# path = self.path -# else: -# path = self.ori_path params = {} for param_obj in self.params: param = param_obj.to_param( @@ -315,12 +311,15 @@ class JinjaCalculation(Calculation): add_help=False, params: Optional[dict] = None, ): - variable = objectspace.paths[path] + internal_variable = path jinja_path = f"{self.attribute_name}_{path}" idx = 0 while jinja_path in objectspace.jinja: jinja_path = f"{self.attribute_name}_{path}_{idx}" idx += 1 + if self.ori_path is not None: + path = self.ori_path + variable = objectspace.paths[path] objectspace.jinja[jinja_path] = self.jinja if return_type in RENAME_TYPE: warning = _('the variable "{0}" has a depreciated return_type "{1}", please use "{2}" instead in {3}') @@ -338,7 +337,7 @@ class JinjaCalculation(Calculation): "__internal_multi": multi, "__internal_files": self.xmlfiles, "__internal_attribute": self.attribute_name, - "__internal_variable": path, + "__internal_variable": internal_variable, }, } if self.default_values: @@ -349,10 +348,6 @@ class JinjaCalculation(Calculation): default["params"] |= self.get_params(objectspace, path) if params: default["params"] |= params -# if self.ori_path is None: -# path = self.path -# else: -# path = self.ori_path if self.warnings: default["warnings_only"] = True for sub_variable, identifier, true_path in get_jinja_variable_to_param( @@ -389,6 +384,8 @@ class JinjaCalculation(Calculation): path, ) -> dict: if self.attribute_name in ["default", "secret_manager"]: + if self.ori_path is not None: + path = self.ori_path if self.return_type: raise Exception("return_type not allowed!") variable = objectspace.paths[path] @@ -411,10 +408,8 @@ class JinjaCalculation(Calculation): if return_type is None: return_type = "string" if return_type not in ["string", "boolean"]: - # if self.ori_path is None: - # path = path - # else: - # path = self.ori_path + if self.ori_path is not None: + path = self.ori_path msg = _( 'variable "{0}" has a calculating "{1}" with an invalid return_type, should be boolean or string, not "{2}"' ).format(path, self.attribute_name, return_type) @@ -422,9 +417,13 @@ class JinjaCalculation(Calculation): if return_type == 'boolean': description = self.description if description is None: + if self.ori_path is not None: + opath = self.ori_path + else: + opath = path warning = _('the variable "{0}" has a return_type "{1}", for attribute "{2}" but has not description in {3}') warn( - warning.format(path, return_type, self.attribute_name, display_xmlfiles(self.xmlfiles)), + warning.format(opath, return_type, self.attribute_name, display_xmlfiles(self.xmlfiles)), RougailWarning, ) self.description = _('value is invalid') @@ -443,10 +442,8 @@ class JinjaCalculation(Calculation): if return_type is None: return_type = "string" if return_type not in ["string", "boolean"]: - # if self.ori_path is None: - # path = .path - # else: - # path = self.ori_path + if self.ori_path is not None: + path = self.ori_path msg = _( 'variable "{0}" has a calculating "{1}" with an invalid return_type, should be boolean or string, not "{2}"' ).format(path, self.attribute_name, return_type) @@ -501,10 +498,6 @@ class _VariableCalculation(Calculation): objectspace, path, ) -> "Variable": - # if self.ori_path is None: - # path = self.path - # else: - # path = self.ori_path if self.version != "1.0" and objectspace.paths.regexp_relative.search( self.variable ): @@ -549,10 +542,6 @@ class _VariableCalculation(Calculation): ): if not variable_in_calculation: if not objectspace.force_optional: - # if self.ori_path is None: - # path = self.path - # else: - # path = self.ori_path msg = _( 'variable "{0}" has an attribute "{1}" calculated with the unknown variable "{2}"' ).format(path, self.attribute_name, self.variable) @@ -589,10 +578,6 @@ class _VariableCalculation(Calculation): def check_multi( self, objectspace, path, variable_in_calculation_path, variable_in_calculation ): - # if self.ori_path is None: - # path = self.path - # else: - # path = self.ori_path local_variable = objectspace.paths[path] local_variable_multi, variable_in_calculation_multi = ( calc_multi_for_type_variable( @@ -742,6 +727,8 @@ class VariableCalculation(_VariableCalculation): objectspace, path, ) -> dict: + if self.ori_path is not None: + path = self.ori_path if ( self.attribute_name != "default" and self.optional @@ -760,7 +747,7 @@ class VariableCalculation(_VariableCalculation): self.optional or objectspace.force_optional ): if self.default is not undefined: - return self.get_default_value_optional(objectspace, self.default) + return self.get_default_value_optional(objectspace, path, self.default) if self.default_values is not None: return self.default_values raise VariableCalculationDependencyError() @@ -798,6 +785,8 @@ class VariablePropertyCalculation(_VariableCalculation): objectspace, path, ) -> dict: + if self.ori_path is not None: + path = self.ori_path ( variable_in_calculation_path, variable_in_calculation, @@ -818,7 +807,7 @@ class VariablePropertyCalculation(_VariableCalculation): ) msg = msg.format(path, self.attribute_name, default) raise DictConsistencyError(msg, 79, self.xmlfiles) - return self.get_default_value_optional(objectspace, default) + return self.get_default_value_optional(objectspace, path, default) params = self.get_params( objectspace, path, @@ -887,6 +876,8 @@ class InformationCalculation(Calculation): objectspace, path, ) -> dict: + if self.ori_path is not None: + path = self.ori_path params = { None: [ { @@ -896,10 +887,6 @@ class InformationCalculation(Calculation): ] } if self.variable: - # if self.ori_path is None: - # path = self.path - # else: - # path = self.ori_path variable, identifier = objectspace.paths.get_with_dynamic( self.variable, path, @@ -965,6 +952,7 @@ class IdentifierPropertyCalculation(_IdentifierCalculation): def to_function( self, objectspace, + path, ) -> dict: if self.version == "1.0": msg = _( diff --git a/src/rougail/user_data.py b/src/rougail/user_data.py index 08c0e7cc1..ad5847f81 100644 --- a/src/rougail/user_data.py +++ b/src/rougail/user_data.py @@ -272,13 +272,6 @@ class UserData: if path != option.path(): self.values[option.path()] = self.values.pop(values_path) else: - if "source" in self.values[values_path]: - option_without_index.information.set( - "loaded_from", - _("loaded from {0}").format( - self.values[values_path]["source"] - ), - ) # value is correctly set, remove variable to the set if index is not None: # if it's a follower waiting for all followers are sets @@ -401,7 +394,10 @@ class UserData: if not isinstance(value, tuple): indexes = range(len(value)) else: - indexes = range(len(option.parent().leader().value.get())) + try: + indexes = range(len(option.parent().leader().value.get())) + except: + continue values = value else: indexes = [None] @@ -544,9 +540,11 @@ class UserData: def set_value(self, option, value, options, index): is_secret_manager = options.get("secret_manager", False) + option_without_index = option if is_secret_manager and isinstance(value, tuple): # it's a function params = tuple([ParamValue(val) for val in value[1:]]) + option.information.set('secret_manager', True) if index is not None: option = option.forcepermissive.index(index) value = Calculation(value[0], Params(params, kwargs={"option": ParamValue(option)})) @@ -559,6 +557,25 @@ class UserData: option.value.set(value) if add_validation: option.property.add("validator") + path = option.path() + if "source" in self.values[path]: + if option.isfollower(): + key = f"loaded_from_{index}" + else: + key = "loaded_from" + value = _("loaded from {0}").format( + self.values[path]["source"] + ) + if options.get("secret_manager"): + # FIXME (true_config ???) + default = option.value.default() + if option.isleader(): + default = default[0] + value = _('{0} (the search key is "{1}")').format(value, default) + option_without_index.information.set( + key, + value, + ) def convert_value(option, value, needs_convert): diff --git a/src/rougail/utils.py b/src/rougail/utils.py index 334e7b5df..007492462 100644 --- a/src/rougail/utils.py +++ b/src/rougail/utils.py @@ -128,7 +128,6 @@ def get_jinja_variable_to_param( break else: unknown_variables.append(variable_path) - for variable_path in unknown_variables: for v in founded_variables: if get_common_path(v, variable_path) == v: diff --git a/tests/dictionaries/04_5disabled_calculation_variable11/makedict/after.json b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/after.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/after.json @@ -0,0 +1 @@ +{} diff --git a/tests/dictionaries/04_5disabled_calculation_variable11/makedict/base.json b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/base.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/base.json @@ -0,0 +1 @@ +{} diff --git a/tests/dictionaries/04_5disabled_calculation_variable11/makedict/before.json b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/before.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/before.json @@ -0,0 +1 @@ +{} diff --git a/tests/dictionaries/04_5disabled_calculation_variable11/makedict/mandatory.json b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/mandatory.json new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/mandatory.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/dictionaries/04_5disabled_calculation_variable11/makedict/read_write.json b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/read_write.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/dictionaries/04_5disabled_calculation_variable11/makedict/read_write.json @@ -0,0 +1 @@ +{} diff --git a/tests/dictionaries/04_5disabled_calculation_variable11/tiramisu/base.py b/tests/dictionaries/04_5disabled_calculation_variable11/tiramisu/base.py new file mode 100644 index 000000000..8b898a866 --- /dev/null +++ b/tests/dictionaries/04_5disabled_calculation_variable11/tiramisu/base.py @@ -0,0 +1,16 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_2 = BoolOption(name="condition", doc="a condition", default=True, properties=frozenset({"disabled", "mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_variable11/rougail/00-base.yml'], 'type': 'boolean'}) +option_3 = StrOption(name="variable", doc="a variable", properties=frozenset({"basic", "mandatory", Calculation(func['variable_to_property'], Params((), kwargs={'value': ParamOption(option_2, raisepropertyerror=True), 'prop': ParamValue("disabled"), 'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_variable11/rougail/00-base.yml'], 'type': 'string'}) +optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3], properties=frozenset({"basic"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/04_5disabled_calculation_variable11/tiramisu/no_namespace.py b/tests/dictionaries/04_5disabled_calculation_variable11/tiramisu/no_namespace.py new file mode 100644 index 000000000..9d90d9e75 --- /dev/null +++ b/tests/dictionaries/04_5disabled_calculation_variable11/tiramisu/no_namespace.py @@ -0,0 +1,15 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_1 = BoolOption(name="condition", doc="a condition", default=True, properties=frozenset({"disabled", "mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_variable11/rougail/00-base.yml'], 'type': 'boolean'}) +option_2 = StrOption(name="variable", doc="a variable", properties=frozenset({"basic", "mandatory", Calculation(func['variable_to_property'], Params((), kwargs={'value': ParamOption(option_1, raisepropertyerror=True), 'prop': ParamValue("disabled"), 'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_variable11/rougail/00-base.yml'], 'type': 'string'}) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2]) diff --git a/tests/dictionaries/44_5leadership_leader_hidden_calculation/tiramisu/base.py b/tests/dictionaries/44_5leadership_leader_hidden_calculation/tiramisu/base.py index d92c22ada..3b86640a6 100644 --- a/tests/dictionaries/44_5leadership_leader_hidden_calculation/tiramisu/base.py +++ b/tests/dictionaries/44_5leadership_leader_hidden_calculation/tiramisu/base.py @@ -12,10 +12,10 @@ ALLOWED_LEADER_PROPERTIES.add("standard") ALLOWED_LEADER_PROPERTIES.add("advanced") dict_env['frozen_rougail.leader.leader'] = "{% if __.condition == \"no\" %}\ncondition is no\n{% endif %}\n" dict_env['frozen_rougail.leader.follower'] = "{% if __.condition == \"no\" %}\ncondition is no\n{% endif %}\n" -dict_env['hidden_rougail.leader.leader'] = "{% if __.condition == \"no\" %}\ncondition is no\n{% endif %}\n" +dict_env['hidden_rougail.leader'] = "{% if __.condition == \"no\" %}\ncondition is no\n{% endif %}\n" option_2 = StrOption(name="condition", doc="a condition", default="no", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml'], 'type': 'string'}) option_4 = StrOption(name="leader", doc="a leader", multi=True, properties=frozenset({"force_default_on_freeze", "standard", Calculation(func['jinja_to_property'], Params((ParamValue("frozen"), ParamValue("if condition is no")), kwargs={'__internal_jinja': ParamValue("frozen_rougail.leader.leader"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']), '__internal_attribute': ParamValue("frozen"), '__internal_variable': ParamValue("rougail.leader.leader"), 'when': ParamValue(True), 'inverse': ParamValue(False), '__.condition': ParamOption(option_2, notraisepropertyerror=True)}), help_function=func['jinja_to_property_help'])}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml'], 'type': 'string'}) option_5 = StrOption(name="follower", doc="a follower", multi=True, properties=frozenset({"basic", "force_default_on_freeze", "mandatory", Calculation(func['jinja_to_property'], Params((ParamValue("frozen"), ParamValue("if condition is no")), kwargs={'__internal_jinja': ParamValue("frozen_rougail.leader.follower"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']), '__internal_attribute': ParamValue("frozen"), '__internal_variable': ParamValue("rougail.leader.follower"), 'when': ParamValue(True), 'inverse': ParamValue(False), '__.condition': ParamOption(option_2, notraisepropertyerror=True)}), help_function=func['jinja_to_property_help'])}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml'], 'type': 'string'}) -optiondescription_3 = Leadership(name="leader", doc="a leadership", children=[option_4, option_5], properties=frozenset({"basic", Calculation(func['jinja_to_property'], Params((ParamValue("hidden"), ParamValue("if condition is no")), kwargs={'__internal_jinja': ParamValue("hidden_rougail.leader.leader"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']), '__internal_attribute': ParamValue("hidden"), '__internal_variable': ParamValue("rougail.leader.leader"), 'when': ParamValue(True), 'inverse': ParamValue(False), '__.condition': ParamOption(option_2, notraisepropertyerror=True)}), help_function=func['jinja_to_property_help'])}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']}) +optiondescription_3 = Leadership(name="leader", doc="a leadership", children=[option_4, option_5], properties=frozenset({"basic", Calculation(func['jinja_to_property'], Params((ParamValue("hidden"), ParamValue("if condition is no")), kwargs={'__internal_jinja': ParamValue("hidden_rougail.leader"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']), '__internal_attribute': ParamValue("hidden"), '__internal_variable': ParamValue("rougail.leader"), 'when': ParamValue(True), 'inverse': ParamValue(False), '__.condition': ParamOption(option_2, notraisepropertyerror=True)}), help_function=func['jinja_to_property_help'])}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']}) optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, optiondescription_3], properties=frozenset({"basic"})) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/44_5leadership_leader_hidden_calculation/tiramisu/no_namespace.py b/tests/dictionaries/44_5leadership_leader_hidden_calculation/tiramisu/no_namespace.py index eb5e83d4b..ff4076cab 100644 --- a/tests/dictionaries/44_5leadership_leader_hidden_calculation/tiramisu/no_namespace.py +++ b/tests/dictionaries/44_5leadership_leader_hidden_calculation/tiramisu/no_namespace.py @@ -12,9 +12,9 @@ ALLOWED_LEADER_PROPERTIES.add("standard") ALLOWED_LEADER_PROPERTIES.add("advanced") dict_env['frozen_leader.leader'] = "{% if __.condition == \"no\" %}\ncondition is no\n{% endif %}\n" dict_env['frozen_leader.follower'] = "{% if __.condition == \"no\" %}\ncondition is no\n{% endif %}\n" -dict_env['hidden_leader.leader'] = "{% if __.condition == \"no\" %}\ncondition is no\n{% endif %}\n" +dict_env['hidden_leader'] = "{% if __.condition == \"no\" %}\ncondition is no\n{% endif %}\n" option_1 = StrOption(name="condition", doc="a condition", default="no", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml'], 'type': 'string'}) option_3 = StrOption(name="leader", doc="a leader", multi=True, properties=frozenset({"force_default_on_freeze", "standard", Calculation(func['jinja_to_property'], Params((ParamValue("frozen"), ParamValue("if condition is no")), kwargs={'__internal_jinja': ParamValue("frozen_leader.leader"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']), '__internal_attribute': ParamValue("frozen"), '__internal_variable': ParamValue("leader.leader"), 'when': ParamValue(True), 'inverse': ParamValue(False), '__.condition': ParamOption(option_1, notraisepropertyerror=True)}), help_function=func['jinja_to_property_help'])}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml'], 'type': 'string'}) option_4 = StrOption(name="follower", doc="a follower", multi=True, properties=frozenset({"basic", "force_default_on_freeze", "mandatory", Calculation(func['jinja_to_property'], Params((ParamValue("frozen"), ParamValue("if condition is no")), kwargs={'__internal_jinja': ParamValue("frozen_leader.follower"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']), '__internal_attribute': ParamValue("frozen"), '__internal_variable': ParamValue("leader.follower"), 'when': ParamValue(True), 'inverse': ParamValue(False), '__.condition': ParamOption(option_1, notraisepropertyerror=True)}), help_function=func['jinja_to_property_help'])}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml'], 'type': 'string'}) -optiondescription_2 = Leadership(name="leader", doc="a leadership", children=[option_3, option_4], properties=frozenset({"basic", Calculation(func['jinja_to_property'], Params((ParamValue("hidden"), ParamValue("if condition is no")), kwargs={'__internal_jinja': ParamValue("hidden_leader.leader"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']), '__internal_attribute': ParamValue("hidden"), '__internal_variable': ParamValue("leader.leader"), 'when': ParamValue(True), 'inverse': ParamValue(False), '__.condition': ParamOption(option_1, notraisepropertyerror=True)}), help_function=func['jinja_to_property_help'])}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']}) +optiondescription_2 = Leadership(name="leader", doc="a leadership", children=[option_3, option_4], properties=frozenset({"basic", Calculation(func['jinja_to_property'], Params((ParamValue("hidden"), ParamValue("if condition is no")), kwargs={'__internal_jinja': ParamValue("hidden_leader"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '__internal_files': ParamValue(['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']), '__internal_attribute': ParamValue("hidden"), '__internal_variable': ParamValue("leader"), 'when': ParamValue(True), 'inverse': ParamValue(False), '__.condition': ParamOption(option_1, notraisepropertyerror=True)}), help_function=func['jinja_to_property_help'])}), informations={'ymlfiles': ['../rougail-tests/structures/44_5leadership_leader_hidden_calculation/rougail/00-base.yml']}) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, optiondescription_2]) diff --git a/tests/test_types.py b/tests/test_types.py index ce0e7f028..47def1a95 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -44,12 +44,7 @@ def type_variable(test_name): loaded_configuration = load(fh) assert loaded_configuration == loads(dumps(configuration)), f"error in file {variables_file}" # - print('--------------') - print('--------------') - print('--------------') - print(config.value.get()) config.property.read_write() - print(config.value.get()) variables_file = result / "variables_rw.json" configuration = dict(config_to_dict(config.value.get())) if not variables_file.is_file(): diff --git a/tests/types/result/family/variables_rw.json b/tests/types/result/family/variables_rw.json new file mode 100644 index 000000000..1147da561 --- /dev/null +++ b/tests/types/result/family/variables_rw.json @@ -0,0 +1,3 @@ +{ + "rougail.my_family.my_type": "a value" +} \ No newline at end of file diff --git a/tests/types/result/family_redefine/variables_rw.json b/tests/types/result/family_redefine/variables_rw.json new file mode 100644 index 000000000..95151a824 --- /dev/null +++ b/tests/types/result/family_redefine/variables_rw.json @@ -0,0 +1,8 @@ +{ + "rougail.my_family_1.a_first_variable": "a modified value", + "rougail.my_family_1.a_second_variable": "a modified value", + "rougail.my_family_2.a_first_variable": "a value", + "rougail.my_family_2.a_second_variable": null, + "rougail.my_family_3.a_first_variable": "a value", + "rougail.my_family_3.a_second_variable": "a modified value 2" +} \ No newline at end of file diff --git a/tests/types/result/family_subfamily/variables_rw.json b/tests/types/result/family_subfamily/variables_rw.json new file mode 100644 index 000000000..76f7ca42d --- /dev/null +++ b/tests/types/result/family_subfamily/variables_rw.json @@ -0,0 +1,8 @@ +{ + "rougail.my_family_1.a_first_variable": "a modified value", + "rougail.my_family_1.a_sub_family.a_second_variable": "a modified value", + "rougail.my_family_2.a_first_variable": "a value", + "rougail.my_family_2.a_sub_family.a_second_variable": null, + "rougail.my_family_3.a_first_variable": "a value", + "rougail.my_family_3.a_sub_family.a_second_variable": "a modified value 2" +} \ No newline at end of file diff --git a/tests/types/result/variable/variables_rw.json b/tests/types/result/variable/variables_rw.json new file mode 100644 index 000000000..3b31efb64 --- /dev/null +++ b/tests/types/result/variable/variables_rw.json @@ -0,0 +1,3 @@ +{ + "rougail.my_var": "a value" +} \ No newline at end of file diff --git a/tests/types/result/variable_hidden/tiramisu.py b/tests/types/result/variable_hidden/tiramisu.py new file mode 100644 index 000000000..0344f224f --- /dev/null +++ b/tests/types/result/variable_hidden/tiramisu.py @@ -0,0 +1,22 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_3 = StrOption(name="a_first_variable", doc="a first variable", default="a modified value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml', 'tests/types/structures/variable_hidden/00_structure.yml'], 'type': 'string'}) +option_4 = StrOption(name="a_second_variable", doc="a second variable", default="a modified value", properties=frozenset({"force_default_on_freeze", "mandatory", "standard", Calculation(func['variable_to_property'], Params((), kwargs={'value': ParamOption(option_3), 'prop': ParamValue("hidden"), 'when': ParamValue("a value"), 'inverse': ParamValue(True)}), help_function=func['variable_to_property']), Calculation(func['variable_to_property'], Params((), kwargs={'value': ParamOption(option_3), 'prop': ParamValue("frozen"), 'when': ParamValue("a value"), 'inverse': ParamValue(True)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml', 'tests/types/structures/variable_hidden/00_structure.yml'], 'type': 'string'}) +optiondescription_2 = OptionDescription(name="my_family_1", doc="My family type", children=[option_3, option_4], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml', 'tests/types/structures/variable_hidden/00_structure.yml']}) +option_6 = StrOption(name="a_first_variable", doc="a first variable", default="a value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml'], 'type': 'string'}) +option_7 = StrOption(name="a_second_variable", doc="a second variable", properties=frozenset({"basic", "force_default_on_freeze", "mandatory", Calculation(func['variable_to_property'], Params((), kwargs={'value': ParamOption(option_6), 'prop': ParamValue("hidden"), 'when': ParamValue("a value"), 'inverse': ParamValue(True)}), help_function=func['variable_to_property']), Calculation(func['variable_to_property'], Params((), kwargs={'value': ParamOption(option_6), 'prop': ParamValue("frozen"), 'when': ParamValue("a value"), 'inverse': ParamValue(True)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml'], 'type': 'string'}) +optiondescription_5 = OptionDescription(name="my_family_2", doc="My family type", children=[option_6, option_7], properties=frozenset({"basic"}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml', 'tests/types/structures/variable_hidden/00_structure.yml']}) +option_9 = StrOption(name="a_first_variable", doc="a first variable", default="a value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml'], 'type': 'string'}) +option_10 = StrOption(name="a_second_variable", doc="a second variable", default="a modified value 2", properties=frozenset({"force_default_on_freeze", "mandatory", "standard", Calculation(func['variable_to_property'], Params((), kwargs={'value': ParamOption(option_9), 'prop': ParamValue("hidden"), 'when': ParamValue("a value"), 'inverse': ParamValue(True)}), help_function=func['variable_to_property']), Calculation(func['variable_to_property'], Params((), kwargs={'value': ParamOption(option_9), 'prop': ParamValue("frozen"), 'when': ParamValue("a value"), 'inverse': ParamValue(True)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml', 'tests/types/structures/variable_hidden/00_structure.yml'], 'type': 'string'}) +optiondescription_8 = OptionDescription(name="my_family_3", doc="My family type", children=[option_9, option_10], properties=frozenset({"standard"}), informations={'ymlfiles': ['tests/types/types/variable_hidden/00_structure.yml', 'tests/types/structures/variable_hidden/00_structure.yml']}) +optiondescription_1 = OptionDescription(name="rougail", doc="rougail", group_type=groups.namespace, children=[optiondescription_2, optiondescription_5, optiondescription_8], properties=frozenset({"basic"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/types/result/variable_hidden/variables.json b/tests/types/result/variable_hidden/variables.json new file mode 100644 index 000000000..4cf273477 --- /dev/null +++ b/tests/types/result/variable_hidden/variables.json @@ -0,0 +1,7 @@ +{ + "rougail.my_family_1.a_first_variable": "a modified value", + "rougail.my_family_2.a_first_variable": "a value", + "rougail.my_family_2.a_second_variable": null, + "rougail.my_family_3.a_first_variable": "a value", + "rougail.my_family_3.a_second_variable": "a modified value 2" +} \ No newline at end of file diff --git a/tests/types/result/variable_hidden/variables_rw.json b/tests/types/result/variable_hidden/variables_rw.json new file mode 100644 index 000000000..4cf273477 --- /dev/null +++ b/tests/types/result/variable_hidden/variables_rw.json @@ -0,0 +1,7 @@ +{ + "rougail.my_family_1.a_first_variable": "a modified value", + "rougail.my_family_2.a_first_variable": "a value", + "rougail.my_family_2.a_second_variable": null, + "rougail.my_family_3.a_first_variable": "a value", + "rougail.my_family_3.a_second_variable": "a modified value 2" +} \ No newline at end of file diff --git a/tests/types/result/variables/variables_rw.json b/tests/types/result/variables/variables_rw.json new file mode 100644 index 000000000..189bbb970 --- /dev/null +++ b/tests/types/result/variables/variables_rw.json @@ -0,0 +1,5 @@ +{ + "rougail.my_var1": "a value", + "rougail.my_var2": "a value", + "rougail.my_var3": null +} \ No newline at end of file