feat: suffixes in dynamic family should be a jinja function #5

Merged
gremond merged 6 commits from new_dynamic into develop 2024-03-28 09:43:34 +01:00
3 changed files with 31 additions and 14 deletions
Showing only changes of commit d2244c7bc5 - Show all commits

View file

@ -73,3 +73,15 @@ class DictConsistencyError(Exception):
class UpgradeError(Exception): class UpgradeError(Exception):
"""Error during XML upgrade""" """Error during XML upgrade"""
## ---- generic exceptions ----
class NotFoundError(Exception):
"not found error"
pass
class VariableNotFoundError(NotFoundError):
"Variable was not found"
def __init__(self, errmsg, varname):
self.varname = varname

View file

@ -30,7 +30,7 @@ from pydantic import (
ConfigDict, ConfigDict,
) )
from .utils import get_jinja_variable_to_param, get_realpath from .utils import get_jinja_variable_to_param, get_realpath
from .error import VariableNotFoundError
BASETYPE = Union[StrictBool, StrictInt, StrictFloat, StrictStr, None] BASETYPE = Union[StrictBool, StrictInt, StrictFloat, StrictStr, None]
@ -303,8 +303,9 @@ class VariableCalculation(Calculation):
variable_path = self.get_realpath(self.variable) variable_path = self.get_realpath(self.variable)
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(variable_path) variable, suffix, dynamic = objectspace.paths.get_with_dynamic(variable_path)
if not variable: if not variable:
raise Exception(f"pffff {variable_path}") raise VariableNotFoundError(f"Variable not found {variable_path}", variable_path)
if not isinstance(variable, objectspace.variable): if not isinstance(variable, objectspace.variable):
# FIXME remove the pfff
raise Exception("pfff it's a family") raise Exception("pfff it's a family")
param = { param = {
"type": "variable", "type": "variable",

View file

@ -33,7 +33,7 @@ from json import dumps
from os.path import isfile, basename from os.path import isfile, basename
from .i18n import _ from .i18n import _
from .error import DictConsistencyError from .error import DictConsistencyError, VariableNotFoundError
from .utils import normalize_family from .utils import normalize_family
from .object_model import Calculation, CONVERT_OPTION from .object_model import Calculation, CONVERT_OPTION
@ -575,15 +575,19 @@ class Family(Common):
children = [] children = []
for path in self.objectspace.parents[self.elt.path]: for path in self.objectspace.parents[self.elt.path]:
children.append(self.objectspace.paths[path]) children.append(self.objectspace.paths[path])
keys["children"] = ( try:
"[" keys["children"] = (
+ ", ".join( "["
[ + ", ".join(
self.tiramisu.reflector_objects[child.path].get( [
self.calls, self.elt.path self.tiramisu.reflector_objects[child.path].get(
) self.calls, self.elt.path
for child in children )
] for child in children
]
)
+ "]"
) )
+ "]" except VariableNotFoundError as exc:
) msg = f"The variable '{exc.varname}' is mandatory for the dynamic family"
raise DictConsistencyError(msg, 88, self.elt.xmlfiles)