From 0271bf430af20868f2b4a1d9fecf025350484835 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 14 Mar 2026 21:24:57 +0100 Subject: [PATCH] fix: better identifier support --- src/rougail/output_doc/annotator.py | 72 +++++++++++++++-------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/rougail/output_doc/annotator.py b/src/rougail/output_doc/annotator.py index fd39e38b4..84db3df77 100644 --- a/src/rougail/output_doc/annotator.py +++ b/src/rougail/output_doc/annotator.py @@ -38,6 +38,10 @@ from rougail.convert.object_model import ( NamespaceCalculation, CONVERT_OPTION, ) +try: + from rougail.user_data_risotto.utils import RisottoCalculation +except ImportError as err: + RisottoCalculation = None class Annotator(Walk): @@ -290,13 +294,13 @@ class Annotator(Walk): return self.calculation_to_information_information( values, version, path ) - if isinstance(values, (IdentifierCalculation, IdentifierPropertyCalculation)): - return { - "type": "identifier", - "value": self.calculation_to_information_identifier( - values, prop, version - ), - } + if isinstance(values, IdentifierPropertyCalculation): + ret = {} + self.when_to_condition(values, ret) + ret["type"] = "identifier" + return ret + if isinstance(values, IdentifierCalculation): + return {"type": "identifier"} if isinstance(values, IndexCalculation): return { "type": "index", @@ -307,43 +311,53 @@ class Annotator(Walk): "type": "namespace", "value": True, } + if RisottoCalculation and isinstance(values, RisottoCalculation): + # FIXME + return { + "type": "risotto", + "value": True, + } raise Exception(f'unknown calculation {type(values)} "{values}"') def calculation_to_information_variable( self, variable_path: str, values, prop: str, version: str, path: str ) -> str: - # is optional - variable = self.objectspace.paths.get_with_dynamic( + variable, identifiers = self.objectspace.paths.get_with_dynamic( variable_path, path, values.version, values.namespace, values.xmlfiles, - )[0] + ) if not variable or (isinstance(values, VariableCalculation) and values.optional and not variable): return None values_calculation = {"path": variable.path} + if identifiers: + values_calculation["identifiers"] = identifiers if prop in PROPERTY_ATTRIBUTE: # get comparative value # values_calculation["transitive"] = values.propertyerror == "transitive" - if values.when_not is not undefined: - values_calculation["type"] = "condition" - values_calculation["value"] = values.when_not - values_calculation["condition"] = "when_not" - elif values.when is not undefined: - values_calculation["type"] = "condition" - values_calculation["value"] = values.when - values_calculation["condition"] = "when" - elif values.propertyerror == "transitive": - values_calculation["type"] = "transitive" - else: - values_calculation["type"] = "condition" - values_calculation["value"] = True - values_calculation["condition"] = "when" + self.when_to_condition(values, values_calculation) else: values_calculation["type"] = "variable" return values_calculation + def when_to_condition(self, values, values_calculation): + if values.when_not is not undefined: + values_calculation["type"] = "condition" + values_calculation["value"] = values.when_not + values_calculation["condition"] = "when_not" + elif values.when is not undefined: + values_calculation["type"] = "condition" + values_calculation["value"] = values.when + values_calculation["condition"] = "when" + elif values.propertyerror == "transitive": + values_calculation["type"] = "transitive" + else: + values_calculation["type"] = "condition" + values_calculation["value"] = True + values_calculation["condition"] = "when" + def calculation_to_information_information( self, values, version: str, path: str ) -> Union[str, bool]: @@ -363,16 +377,6 @@ class Annotator(Walk): values_calculation["path"] = variable.path return values_calculation - def calculation_to_information_identifier( - self, values, prop: str, version: str - ) -> Union[str, bool]: - if version != "1.0" and prop in PROPERTY_ATTRIBUTE: - if values.when is not undefined: - return _('when the identifier is "{0}"').format(values.when) - if values.when_not is not undefined: - return _('when the identifier is not "{0}"').format(values.when_not) - return True - def get_path_from_variable(self, values, version: str, path: str) -> str: variable_path = values.variable paths = self.objectspace.paths