From 4bf727487165d8b39446286992cc4e3a32017dd6 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 29 Sep 2025 21:19:13 +0200 Subject: [PATCH] fix: better doc for calculation with unknown variable --- src/rougail/convert/object_model.py | 10 ++++++---- src/rougail/convert/tiramisureflector.py | 20 +++++++++++++++----- src/rougail/tiramisu.py | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/rougail/convert/object_model.py b/src/rougail/convert/object_model.py index 797934599..765a2f917 100644 --- a/src/rougail/convert/object_model.py +++ b/src/rougail/convert/object_model.py @@ -674,11 +674,13 @@ class VariableCalculation(_VariableCalculation): ) = self.get_variable(objectspace) if ( not variable_in_calculation - and self.optional - or (objectspace.force_optional and self.attribute_name == "default") + and (self.optional + or objectspace.force_optional) ): if self.default is not undefined: return self.get_default_value_optional(objectspace, self.default) + if self.default_values is not None: + return self.default_values raise VariableCalculationDependencyError() if variable_in_calculation and self.attribute_name == "default": local_variable = objectspace.paths[self.path] @@ -720,8 +722,8 @@ class VariablePropertyCalculation(_VariableCalculation): if ( # self.default is not undefined and not variable_in_calculation - and self.optional - or (objectspace.force_optional) + and (self.optional + or objectspace.force_optional) ): if self.default is undefined: default = False diff --git a/src/rougail/convert/tiramisureflector.py b/src/rougail/convert/tiramisureflector.py index f9f610b14..f80846def 100644 --- a/src/rougail/convert/tiramisureflector.py +++ b/src/rougail/convert/tiramisureflector.py @@ -226,7 +226,8 @@ class Common: for val in value: ret = self.calculation_property(val) if isinstance(ret, bool): - properties.append(self.convert_str(property_)) + if ret: + properties.append(self.convert_str(property_)) elif ret is not None: calc_properties.append(ret) if properties or calc_properties: @@ -244,6 +245,7 @@ class Common: return None return value + def calc_properties( self, prop, @@ -462,9 +464,14 @@ class Variable(Common): ) return if self.elt.type == "choice": - keys["values"] = self.populate_calculation( - self.elt.choices, return_a_tuple=True - ) + try: + keys["values"] = self.populate_calculation( + self.elt.choices, return_a_tuple=True + ) + if keys["values"] == '(,)': + keys["values"] = tuple() + except VariableCalculationDependencyError: + keys["values"] = tuple() if self.elt.type == "regexp": self.object_type = "Regexp_" + self.option_name self.tiramisu.text["header"].append( @@ -537,7 +544,10 @@ class Family(Common): if self.group_type: keys["group_type"] = self.group_type if self.elt.type == "dynamic": - keys["identifiers"] = self.populate_calculation(self.elt.dynamic) + try: + keys["identifiers"] = self.populate_calculation(self.elt.dynamic) + except VariableCalculationDependencyError: + keys["identifiers"] = [] children = [] for path in self.objectspace.parents[self.elt.path]: children.append(self.objectspace.paths[path]) diff --git a/src/rougail/tiramisu.py b/src/rougail/tiramisu.py index 60b816e48..271909061 100644 --- a/src/rougail/tiramisu.py +++ b/src/rougail/tiramisu.py @@ -433,7 +433,7 @@ class ConvertDynOptionDescription(DynOptionDescription): if "{{ identifier }}" in display: return display.replace( "{{ identifier }}", - self.convert_identifier_to_path(self.get_identifiers(subconfig)[-1]), + self.convert_identifier_to_path(self.get_identifiers(subconfig, from_display_name=True)[-1]), ) return display