fix: simplify version support
This commit is contained in:
parent
e71d4600d7
commit
b229154df5
11 changed files with 139 additions and 35 deletions
|
|
@ -259,7 +259,6 @@ class ParserVariable:
|
|||
path: str,
|
||||
obj: dict,
|
||||
family_is_leadership: bool,
|
||||
version: str,
|
||||
filename: str,
|
||||
) -> Literal["variable", "family"]:
|
||||
"""Check object to determine if it's a variable or a family"""
|
||||
|
|
@ -303,7 +302,7 @@ class ParserVariable:
|
|||
else:
|
||||
return "variable"
|
||||
else:
|
||||
if version == "1.0":
|
||||
if self.version == "1.0":
|
||||
msg = f'Invalid value for the variable "{path}": "{obj}"'
|
||||
raise DictConsistencyError(msg, 102, [filename])
|
||||
return "variable"
|
||||
|
|
@ -332,7 +331,6 @@ class ParserVariable:
|
|||
name: str,
|
||||
subpath: str,
|
||||
obj: dict,
|
||||
version: str,
|
||||
comment: Optional[str],
|
||||
*,
|
||||
first_variable: bool = False,
|
||||
|
|
@ -347,14 +345,13 @@ class ParserVariable:
|
|||
path = name
|
||||
else:
|
||||
path = f"{subpath}.{name}"
|
||||
if version == "0.1" and not isinstance(obj, dict) and obj is not None:
|
||||
if self.version == "0.1" and not isinstance(obj, dict) and obj is not None:
|
||||
msg = f'the variable "{path}" has a wrong type "{type(obj)}"'
|
||||
raise DictConsistencyError(msg, 17, [filename])
|
||||
typ = self.is_family_or_variable(
|
||||
path,
|
||||
obj,
|
||||
family_is_leadership,
|
||||
version,
|
||||
filename,
|
||||
)
|
||||
logging.info("family_or_variable: %s is a %s", path, typ)
|
||||
|
|
@ -367,7 +364,6 @@ class ParserVariable:
|
|||
name,
|
||||
path,
|
||||
obj,
|
||||
version,
|
||||
comment=comment,
|
||||
first_variable=first_variable,
|
||||
family_is_leadership=family_is_leadership,
|
||||
|
|
@ -381,7 +377,6 @@ class ParserVariable:
|
|||
name: str,
|
||||
path: str,
|
||||
obj: Optional[Dict[str, Any]],
|
||||
version: str,
|
||||
*,
|
||||
comment: Optional[str] = None,
|
||||
first_variable: bool = False,
|
||||
|
|
@ -394,7 +389,7 @@ class ParserVariable:
|
|||
obj = {}
|
||||
family_obj = {}
|
||||
subfamily_obj = {}
|
||||
if version != "1.0":
|
||||
if self.version != "1.0":
|
||||
exists = obj.pop("exists", None)
|
||||
else:
|
||||
exists = None
|
||||
|
|
@ -406,7 +401,7 @@ class ParserVariable:
|
|||
family_obj[key] = value
|
||||
else:
|
||||
subfamily_obj[key] = value
|
||||
if version != "1.0" and not family_obj and comment:
|
||||
if self.version != "1.0" and not family_obj and comment:
|
||||
family_obj["description"] = comment
|
||||
|
||||
if path in self.paths:
|
||||
|
|
@ -423,7 +418,6 @@ class ParserVariable:
|
|||
obj,
|
||||
filename,
|
||||
family_is_dynamic,
|
||||
version,
|
||||
typ="family",
|
||||
)
|
||||
if self.load_unexist_redefine or exists in [None, True]:
|
||||
|
|
@ -481,7 +475,6 @@ class ParserVariable:
|
|||
filename,
|
||||
family_is_dynamic,
|
||||
parent_dynamic,
|
||||
version,
|
||||
)
|
||||
force_not_first = False
|
||||
if self.paths[path].type == "leadership":
|
||||
|
|
@ -495,7 +488,6 @@ class ParserVariable:
|
|||
key,
|
||||
path,
|
||||
value,
|
||||
version,
|
||||
comment,
|
||||
first_variable=first_variable,
|
||||
family_is_leadership=family_is_leadership,
|
||||
|
|
@ -553,17 +545,16 @@ class ParserVariable:
|
|||
filename: str,
|
||||
family_is_dynamic: bool,
|
||||
parent_dynamic: str,
|
||||
version: str,
|
||||
) -> None:
|
||||
"""Add a new family"""
|
||||
family["path"] = path
|
||||
family["namespace"] = self.namespace
|
||||
family["version"] = version
|
||||
family["version"] = self.version
|
||||
family["xmlfiles"] = [filename]
|
||||
obj_type = self.get_family_or_variable_type(family)
|
||||
if obj_type == "dynamic":
|
||||
family_obj = self.dynamic
|
||||
if version == "1.0":
|
||||
if self.version == "1.0":
|
||||
if "variable" not in family:
|
||||
raise DictConsistencyError(
|
||||
f'dynamic family must have "variable" attribute for "{path}"',
|
||||
|
|
@ -592,7 +583,7 @@ class ParserVariable:
|
|||
"allow_none": True,
|
||||
}
|
||||
del family["variable"]
|
||||
if version != "1.0":
|
||||
if self.version != "1.0":
|
||||
warning = f'"variable" attribute in dynamic family "{ path }" is depreciated in {filename}'
|
||||
warn(warning)
|
||||
if "variable" in family:
|
||||
|
|
@ -607,7 +598,6 @@ class ParserVariable:
|
|||
family,
|
||||
filename,
|
||||
family_is_dynamic,
|
||||
version,
|
||||
typ="family",
|
||||
)
|
||||
try:
|
||||
|
|
@ -637,7 +627,6 @@ class ParserVariable:
|
|||
name: str,
|
||||
path: str,
|
||||
obj: Optional[Dict[str, Any]],
|
||||
version: str,
|
||||
*,
|
||||
comment: Optional[str] = None,
|
||||
first_variable: bool = False,
|
||||
|
|
@ -646,7 +635,7 @@ class ParserVariable:
|
|||
parent_dynamic: Optional[str] = None,
|
||||
) -> None:
|
||||
"""Parse variable"""
|
||||
if version == "1.0" or isinstance(obj, dict):
|
||||
if self.version == "1.0" or isinstance(obj, dict):
|
||||
if obj is None:
|
||||
obj = {}
|
||||
extra_attrs = set(obj) - self.variable_attrs
|
||||
|
|
@ -666,10 +655,9 @@ class ParserVariable:
|
|||
obj,
|
||||
filename,
|
||||
family_is_dynamic,
|
||||
version,
|
||||
)
|
||||
self.parse_params(path, obj, filename)
|
||||
self.parse_secret_manager(path, obj, filename, version, family_is_dynamic)
|
||||
self.parse_secret_manager(path, obj, filename, family_is_dynamic)
|
||||
exists = obj.pop("exists", None)
|
||||
if path in self.paths:
|
||||
if not self.load_unexist_redefine:
|
||||
|
|
@ -700,7 +688,7 @@ class ParserVariable:
|
|||
raise DictConsistencyError(msg, 46, [filename])
|
||||
obj["path"] = path
|
||||
self.add_variable(
|
||||
name, obj, filename, family_is_dynamic, parent_dynamic, version
|
||||
name, obj, filename, family_is_dynamic, parent_dynamic
|
||||
)
|
||||
if family_is_leadership:
|
||||
if first_variable:
|
||||
|
|
@ -714,7 +702,6 @@ class ParserVariable:
|
|||
obj: dict,
|
||||
filename: str,
|
||||
family_is_dynamic: bool,
|
||||
version: str,
|
||||
*,
|
||||
typ: str = "variable",
|
||||
):
|
||||
|
|
@ -737,7 +724,6 @@ class ParserVariable:
|
|||
value,
|
||||
path,
|
||||
family_is_dynamic,
|
||||
version,
|
||||
[filename],
|
||||
)
|
||||
except ValidationError as err:
|
||||
|
|
@ -762,7 +748,6 @@ class ParserVariable:
|
|||
val,
|
||||
path,
|
||||
family_is_dynamic,
|
||||
version,
|
||||
[filename],
|
||||
inside_list=True,
|
||||
index=idx,
|
||||
|
|
@ -808,7 +793,7 @@ class ParserVariable:
|
|||
) from err
|
||||
obj["params"] = params
|
||||
|
||||
def parse_secret_manager(self, path, obj, filename, version, family_is_dynamic):
|
||||
def parse_secret_manager(self, path, obj, filename, family_is_dynamic):
|
||||
"""Parse variable secret_manager"""
|
||||
if "secret_manager" not in obj:
|
||||
return
|
||||
|
|
@ -828,7 +813,6 @@ class ParserVariable:
|
|||
secret_manager,
|
||||
path,
|
||||
family_is_dynamic,
|
||||
version,
|
||||
[filename],
|
||||
)
|
||||
|
||||
|
|
@ -839,7 +823,6 @@ class ParserVariable:
|
|||
filename: str,
|
||||
family_is_dynamic: bool,
|
||||
parent_dynamic: Optional[str],
|
||||
version: str,
|
||||
) -> None:
|
||||
if "{ suffix" in variable["path"]:
|
||||
raise Exception()
|
||||
|
|
@ -848,7 +831,7 @@ class ParserVariable:
|
|||
filename = [filename]
|
||||
|
||||
variable["namespace"] = self.namespace
|
||||
variable["version"] = version
|
||||
variable["version"] = self.version
|
||||
variable["xmlfiles"] = filename
|
||||
variable_type = self.get_family_or_variable_type(variable)
|
||||
obj = {
|
||||
|
|
@ -943,7 +926,6 @@ class ParserVariable:
|
|||
value: dict,
|
||||
path: str,
|
||||
family_is_dynamic: bool,
|
||||
version: str,
|
||||
xmlfiles: List[str],
|
||||
*,
|
||||
inside_list: bool = False,
|
||||
|
|
@ -956,7 +938,7 @@ class ParserVariable:
|
|||
calculation_object["attribute_name"] = attribute
|
||||
calculation_object["path"] = path
|
||||
calculation_object["inside_list"] = inside_list
|
||||
calculation_object["version"] = version
|
||||
calculation_object["version"] = self.version
|
||||
calculation_object["namespace"] = self.namespace
|
||||
calculation_object["xmlfiles"] = xmlfiles
|
||||
#
|
||||
|
|
@ -980,7 +962,7 @@ class ParserVariable:
|
|||
"type": "any",
|
||||
}
|
||||
else:
|
||||
if version == "1.0" and val["type"] == "suffix":
|
||||
if self.version == "1.0" and val["type"] == "suffix":
|
||||
val["type"] = "identifier"
|
||||
param_typ = val["type"]
|
||||
val["key"] = key
|
||||
|
|
@ -1067,6 +1049,7 @@ class RougailConvert(ParserVariable):
|
|||
) -> None:
|
||||
if namespace_path is None:
|
||||
namespace_path = self.namespace
|
||||
self.version = ""
|
||||
self.parse_family(
|
||||
"",
|
||||
self.namespace,
|
||||
|
|
@ -1074,7 +1057,6 @@ class RougailConvert(ParserVariable):
|
|||
{
|
||||
"description": namespace_description,
|
||||
},
|
||||
"",
|
||||
)
|
||||
|
||||
def get_comment(
|
||||
|
|
@ -1097,6 +1079,7 @@ class RougailConvert(ParserVariable):
|
|||
version: str,
|
||||
objects: dict,
|
||||
) -> None:
|
||||
self.version = version
|
||||
for name, obj in objects.items():
|
||||
comment = self.get_comment(name, objects)
|
||||
self.family_or_variable(
|
||||
|
|
@ -1104,7 +1087,6 @@ class RougailConvert(ParserVariable):
|
|||
name,
|
||||
path,
|
||||
obj,
|
||||
version,
|
||||
comment,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -78,11 +78,11 @@ class Annotator(Walk):
|
|||
path = alternative_name
|
||||
else:
|
||||
path = variable_path.rsplit(".", 1)[0] + "." + alternative_name
|
||||
self.objectspace.version = variable.version
|
||||
self.objectspace.add_variable(
|
||||
alternative_name,
|
||||
{"type": "symlink", "path": path, "opt": variable},
|
||||
variable.xmlfiles,
|
||||
False,
|
||||
False,
|
||||
variable.version,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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 = StrOption(name="var1", doc="a first variable", properties=frozenset({"basic", "mandatory"}), informations={'ymlfiles': ['../rougail-tests/structures/00_2default_calculated_variable_description/rougail/00-base.yml'], 'type': 'string'})
|
||||
option_3 = StrOption(name="var2", doc="a second variable", default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_2default_calculated_variable_description/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"}), informations={'ymlfiles': ['']})
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
||||
|
|
@ -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_1 = StrOption(name="var1", doc="a first variable", properties=frozenset({"basic", "mandatory"}), informations={'ymlfiles': ['../rougail-tests/structures/00_2default_calculated_variable_description/rougail/00-base.yml'], 'type': 'string'})
|
||||
option_2 = StrOption(name="var2", doc="a second variable", default=Calculation(func['calc_value'], Params((ParamOption(option_1)))), properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/00_2default_calculated_variable_description/rougail/00-base.yml'], 'type': 'string'})
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2])
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"rougail.var1": {
|
||||
"owner": "default",
|
||||
"value": [
|
||||
"val1",
|
||||
"val2"
|
||||
]
|
||||
},
|
||||
"rougail.dynval1.var": {
|
||||
"owner": "default",
|
||||
"value": "a value"
|
||||
},
|
||||
"rougail.dynval2.var": {
|
||||
"owner": "default",
|
||||
"value": "a value"
|
||||
},
|
||||
"rougail.var2": {
|
||||
"owner": "default",
|
||||
"value": "a value"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"rougail.var1": [
|
||||
"val1",
|
||||
"val2"
|
||||
],
|
||||
"rougail.dynval1.var": "a value",
|
||||
"rougail.dynval2.var": "a value",
|
||||
"rougail.var2": "a value"
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"rougail.var1": {
|
||||
"owner": "default",
|
||||
"value": [
|
||||
"val1",
|
||||
"val2"
|
||||
]
|
||||
},
|
||||
"rougail.dynval1.var": {
|
||||
"owner": "default",
|
||||
"value": "a value"
|
||||
},
|
||||
"rougail.dynval2.var": {
|
||||
"owner": "default",
|
||||
"value": "a value"
|
||||
},
|
||||
"rougail.var2": {
|
||||
"owner": "default",
|
||||
"value": "a value"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
[]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"rougail.var1": [
|
||||
"val1",
|
||||
"val2"
|
||||
],
|
||||
"rougail.var2": "a value"
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
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 = StrOption(name="var1", doc="A suffix variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"standard"}), informations={'ymlfiles': ['../rougail-tests/structures/60_5family_dynamic_calc_suffix_hidden_boolean/rougail/00-base.yml'], 'type': 'string'})
|
||||
option_4 = BoolOption(name="var", doc="A dynamic variable", default=True, properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/60_5family_dynamic_calc_suffix_hidden_boolean/rougail/00-base.yml'], 'type': 'boolean'})
|
||||
optiondescription_3 = ConvertDynOptionDescription(name="dyn{{ identifier }}", doc="dyn{{ identifier }}", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_2)))), children=[option_4], properties=frozenset({"standard"}), informations={'dynamic_variable': 'rougail.var1', 'ymlfiles': ['../rougail-tests/structures/60_5family_dynamic_calc_suffix_hidden_boolean/rougail/00-base.yml']})
|
||||
option_5 = BoolOption(name="var2", doc="A variable calculated", default=Calculation(func['calc_value'], Params((ParamDynOption(option_4, ["val1"])))), properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/60_5family_dynamic_calc_suffix_hidden_boolean/rougail/00-base.yml'], 'type': 'boolean'})
|
||||
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, optiondescription_3, option_5], properties=frozenset({"standard"}), informations={'ymlfiles': ['']})
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
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 = StrOption(name="var1", doc="A suffix variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"standard"}), informations={'ymlfiles': ['../rougail-tests/structures/60_5family_dynamic_calc_suffix_hidden_multi/rougail/00-base.yml'], 'type': 'string'})
|
||||
option_4 = StrOption(name="var", doc="A dynamic variable", multi=True, default=["a value", "a second value"], default_multi="a value", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/60_5family_dynamic_calc_suffix_hidden_multi/rougail/00-base.yml'], 'type': 'string'})
|
||||
optiondescription_3 = ConvertDynOptionDescription(name="dyn{{ identifier }}", doc="dyn{{ identifier }}", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_2)))), children=[option_4], properties=frozenset({"standard"}), informations={'dynamic_variable': 'rougail.var1', 'ymlfiles': ['../rougail-tests/structures/60_5family_dynamic_calc_suffix_hidden_multi/rougail/00-base.yml']})
|
||||
option_5 = StrOption(name="var2", doc="A variable calculated", multi=True, default=Calculation(func['calc_value'], Params((ParamDynOption(option_4, ["val1"])), kwargs={'__internal_multi': ParamValue(True)})), properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['../rougail-tests/structures/60_5family_dynamic_calc_suffix_hidden_multi/rougail/00-base.yml'], 'type': 'string'})
|
||||
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, optiondescription_3, option_5], properties=frozenset({"standard"}), informations={'ymlfiles': ['']})
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
||||
Loading…
Reference in a new issue