feat: for formatter

This commit is contained in:
egarette@silique.fr 2025-09-30 22:02:07 +02:00
parent 899226f7d2
commit f5f55dd853
25 changed files with 161 additions and 19 deletions

View file

@ -320,6 +320,12 @@ class ParserVariable:
return obj["_type"]
if "type" in obj and isinstance(obj["type"], str):
return obj["type"]
if "_dynamic" in obj:
return "dynamic"
if "dynamic" in obj:
dynamic = obj["dynamic"]
if isinstance(dynamic, (list, dict)):
return "dynamic"
return None
###############################################################################################
@ -393,7 +399,8 @@ class ParserVariable:
exists = obj.pop("exists", None)
else:
exists = None
force_to_attrs = list(self.list_attributes(obj, filename))
obj_type = self.get_family_or_variable_type(obj)
force_to_attrs = list(self.list_attributes(obj, filename, obj_type))
for key, value in obj.items():
if key in force_to_attrs:
if key.startswith("_"):
@ -444,18 +451,8 @@ 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":
family_obj["type"] = "dynamic"
family_is_dynamic = True
if "{{ identifier }}" not in name:
if "{{ suffix }}" in name:
@ -499,6 +496,7 @@ class ParserVariable:
self,
obj: Dict[str, Any],
filename: str,
obj_type: str,
) -> Iterator[str]:
"""List attributes"""
force_to_variable = []
@ -535,6 +533,8 @@ class ParserVariable:
):
continue
if key in self.family_attrs:
if obj_type != "dynamic" and key == "dynamic":
continue
yield key
def add_family(
@ -1047,6 +1047,7 @@ class RougailConvert(ParserVariable):
def create_namespace(
self, namespace_description: str, namespace_path: Optional[str] = None
) -> None:
self.has_namespace = True
if namespace_path is None:
namespace_path = self.namespace
self.version = ""

View file

@ -22,5 +22,13 @@
"rougail.var6": {
"owner": "default",
"value": "value"
},
"rougail.var7": {
"owner": "default",
"value": "8080"
},
"rougail.var8": {
"owner": "default",
"value": "true"
}
}

View file

@ -4,5 +4,7 @@
"rougail.var3": null,
"rougail.var4": "value",
"rougail.var5": "value",
"rougail.var6": "value"
"rougail.var6": "value",
"rougail.var7": "8080",
"rougail.var8": "true"
}

View file

@ -22,5 +22,13 @@
"rougail.var6": {
"owner": "default",
"value": "value"
},
"rougail.var7": {
"owner": "default",
"value": "8080"
},
"rougail.var8": {
"owner": "default",
"value": "true"
}
}

View file

@ -4,5 +4,7 @@
"rougail.var3": null,
"rougail.var4": "value",
"rougail.var5": "value",
"rougail.var6": "value"
"rougail.var6": "value",
"rougail.var7": "8080",
"rougail.var8": "true"
}

View file

@ -16,5 +16,7 @@ option_4 = StrOption(name="var3", doc="the third variable", properties=frozenset
option_5 = StrOption(name="var4", doc="the forth variable", default="value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
option_6 = StrOption(name="var5", doc="the fifth variable", default="value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
option_7 = StrOption(name="var6", doc="the sixth variable", default="value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3, option_4, option_5, option_6, option_7], properties=frozenset({"basic"}), informations={'ymlfiles': ['']})
option_8 = StrOption(name="var7", doc="the seventh variable", default="8080", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
option_9 = StrOption(name="var8", doc="the height variable", default="true", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3, option_4, option_5, option_6, option_7, option_8, option_9], properties=frozenset({"basic"}), informations={'ymlfiles': ['']})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -12,4 +12,6 @@ option_3 = StrOption(name="var3", doc="the third variable", properties=frozenset
option_4 = StrOption(name="var4", doc="the forth variable", default="value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
option_5 = StrOption(name="var5", doc="the fifth variable", default="value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
option_6 = StrOption(name="var6", doc="the sixth variable", default="value", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2, option_3, option_4, option_5, option_6])
option_7 = StrOption(name="var7", doc="the seventh variable", default="8080", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
option_8 = StrOption(name="var8", doc="the height variable", default="true", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_6string/rougail/00-base.yml'], 'type': 'string'})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2, option_3, option_4, option_5, option_6, option_7, option_8])

View file

@ -1,5 +1,6 @@
{
"rougail.condition": false,
"rougail.var1": null,
"rougail.var3": null,
"rougail.var4": null
}

View file

@ -11,7 +11,7 @@ ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_2 = BoolOption(name="condition", doc="a condition", default=False, properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'boolean'})
option_3 = StrOption(name="var1", doc="a first variable", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})
option_3 = StrOption(name="var1", doc="a first variable", properties=frozenset({"force_default_on_freeze", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})
option_4 = StrOption(name="var2", doc="a first variable", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})
option_5 = StrOption(name="var3", doc="a second variable", properties=frozenset({"force_default_on_freeze", "standard", Calculation(func['variable_to_property'], Params((ParamValue("hidden"), ParamOption(option_2)), kwargs={'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property']), Calculation(func['variable_to_property'], Params((ParamValue("frozen"), ParamOption(option_2)), kwargs={'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})
option_6 = StrOption(name="var4", doc="a forth variable", properties=frozenset({"force_default_on_freeze", "standard", Calculation(func['variable_to_property'], Params((ParamValue("hidden"), ParamOption(option_2)), kwargs={'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property']), Calculation(func['variable_to_property'], Params((ParamValue("frozen"), ParamOption(option_2)), kwargs={'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})

View file

@ -7,7 +7,7 @@ ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_1 = BoolOption(name="condition", doc="a condition", default=False, properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'boolean'})
option_2 = StrOption(name="var1", doc="a first variable", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})
option_2 = StrOption(name="var1", doc="a first variable", properties=frozenset({"force_default_on_freeze", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})
option_3 = StrOption(name="var2", doc="a first variable", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})
option_4 = StrOption(name="var3", doc="a second variable", properties=frozenset({"force_default_on_freeze", "standard", Calculation(func['variable_to_property'], Params((ParamValue("hidden"), ParamOption(option_1)), kwargs={'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property']), Calculation(func['variable_to_property'], Params((ParamValue("frozen"), ParamOption(option_1)), kwargs={'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})
option_5 = StrOption(name="var4", doc="a forth variable", properties=frozenset({"force_default_on_freeze", "standard", Calculation(func['variable_to_property'], Params((ParamValue("hidden"), ParamOption(option_1)), kwargs={'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property']), Calculation(func['variable_to_property'], Params((ParamValue("frozen"), ParamOption(option_1)), kwargs={'when': ParamValue(True), 'inverse': ParamValue(False)}), help_function=func['variable_to_property'])}), informations={'ymlfiles': ['../rougail-tests/structures/04_5disabled_calculation_optional_default/rougail/00-base.yml'], 'type': 'string'})

View file

@ -0,0 +1,13 @@
{
"rougail.my_family.dynamic": {
"owner": "default",
"value": [
"val1",
"val2"
]
},
"rougail.my_family.var": {
"owner": "default",
"value": true
}
}

View file

@ -0,0 +1,7 @@
{
"rougail.my_family.dynamic": [
"val1",
"val2"
],
"rougail.my_family.var": true
}

View file

@ -0,0 +1,13 @@
{
"rougail.my_family.dynamic": {
"owner": "default",
"value": [
"val1",
"val2"
]
},
"rougail.my_family.var": {
"owner": "default",
"value": true
}
}

View file

@ -0,0 +1,7 @@
{
"rougail.my_family.dynamic": [
"val1",
"val2"
],
"rougail.my_family.var": true
}

View file

@ -0,0 +1,17 @@
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_3 = StrOption(name="dynamic", doc="dynamic", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_dynamic/rougail/00-base.yml'], 'type': 'string'})
option_4 = BoolOption(name="var", doc="a variable", default=True, properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_dynamic/rougail/00-base.yml'], 'type': 'boolean'})
optiondescription_2 = OptionDescription(name="my_family", doc="my_family", children=[option_3, option_4], properties=frozenset({"standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_dynamic/rougail/00-base.yml']})
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[optiondescription_2], properties=frozenset({"standard"}), informations={'ymlfiles': ['']})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,12 @@
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')
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_2 = StrOption(name="dynamic", doc="dynamic", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_dynamic/rougail/00-base.yml'], 'type': 'string'})
option_3 = BoolOption(name="var", doc="a variable", default=True, properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_dynamic/rougail/00-base.yml'], 'type': 'boolean'})
optiondescription_1 = OptionDescription(name="my_family", doc="my_family", children=[option_2, option_3], properties=frozenset({"standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_dynamic/rougail/00-base.yml']})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,6 @@
{
"rougail.my_family.default": {
"owner": "default",
"value": true
}
}

View file

@ -0,0 +1,3 @@
{
"rougail.my_family.default": true
}

View file

@ -0,0 +1,6 @@
{
"rougail.my_family.default": {
"owner": "default",
"value": true
}
}

View file

@ -0,0 +1,3 @@
{
"rougail.my_family.default": true
}

View file

@ -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_3 = BoolOption(name="default", doc="default", default=True, properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_variable/rougail/00-base.yml'], 'type': 'boolean'})
optiondescription_2 = OptionDescription(name="my_family", doc="my_family", children=[option_3], properties=frozenset({"standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_variable/rougail/00-base.yml']})
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[optiondescription_2], properties=frozenset({"standard"}), informations={'ymlfiles': ['']})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,11 @@
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')
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_2 = BoolOption(name="default", doc="default", default=True, properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_variable/rougail/00-base.yml'], 'type': 'boolean'})
optiondescription_1 = OptionDescription(name="my_family", doc="my_family", children=[option_2], properties=frozenset({"standard"}), informations={'ymlfiles': ['../rougail-tests/structures/20_2family_looks_like_variable/rougail/00-base.yml']})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -47,7 +47,7 @@ excludes = set([
])
test_ok -= excludes
test_raise -= excludes
# test_ok = ['01_9choice_variable_optional']
# test_ok = ['60_0family_dynamic']
#test_ok = []
# test_raise = ['80unknown_default_variable_inside_dynamic_family']
#test_raise = []