fix: better identifier support

This commit is contained in:
egarette@silique.fr 2026-03-14 21:24:57 +01:00
parent 48668bce75
commit 0271bf430a

View file

@ -38,6 +38,10 @@ from rougail.convert.object_model import (
NamespaceCalculation, NamespaceCalculation,
CONVERT_OPTION, CONVERT_OPTION,
) )
try:
from rougail.user_data_risotto.utils import RisottoCalculation
except ImportError as err:
RisottoCalculation = None
class Annotator(Walk): class Annotator(Walk):
@ -290,13 +294,13 @@ class Annotator(Walk):
return self.calculation_to_information_information( return self.calculation_to_information_information(
values, version, path values, version, path
) )
if isinstance(values, (IdentifierCalculation, IdentifierPropertyCalculation)): if isinstance(values, IdentifierPropertyCalculation):
return { ret = {}
"type": "identifier", self.when_to_condition(values, ret)
"value": self.calculation_to_information_identifier( ret["type"] = "identifier"
values, prop, version return ret
), if isinstance(values, IdentifierCalculation):
} return {"type": "identifier"}
if isinstance(values, IndexCalculation): if isinstance(values, IndexCalculation):
return { return {
"type": "index", "type": "index",
@ -307,43 +311,53 @@ class Annotator(Walk):
"type": "namespace", "type": "namespace",
"value": True, "value": True,
} }
if RisottoCalculation and isinstance(values, RisottoCalculation):
# FIXME
return {
"type": "risotto",
"value": True,
}
raise Exception(f'unknown calculation {type(values)} "{values}"') raise Exception(f'unknown calculation {type(values)} "{values}"')
def calculation_to_information_variable( def calculation_to_information_variable(
self, variable_path: str, values, prop: str, version: str, path: str self, variable_path: str, values, prop: str, version: str, path: str
) -> str: ) -> str:
# is optional variable, identifiers = self.objectspace.paths.get_with_dynamic(
variable = self.objectspace.paths.get_with_dynamic(
variable_path, variable_path,
path, path,
values.version, values.version,
values.namespace, values.namespace,
values.xmlfiles, values.xmlfiles,
)[0] )
if not variable or (isinstance(values, VariableCalculation) and values.optional and not variable): if not variable or (isinstance(values, VariableCalculation) and values.optional and not variable):
return None return None
values_calculation = {"path": variable.path} values_calculation = {"path": variable.path}
if identifiers:
values_calculation["identifiers"] = identifiers
if prop in PROPERTY_ATTRIBUTE: if prop in PROPERTY_ATTRIBUTE:
# get comparative value # get comparative value
# values_calculation["transitive"] = values.propertyerror == "transitive" # values_calculation["transitive"] = values.propertyerror == "transitive"
if values.when_not is not undefined: self.when_to_condition(values, values_calculation)
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"
else: else:
values_calculation["type"] = "variable" values_calculation["type"] = "variable"
return values_calculation 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( def calculation_to_information_information(
self, values, version: str, path: str self, values, version: str, path: str
) -> Union[str, bool]: ) -> Union[str, bool]:
@ -363,16 +377,6 @@ class Annotator(Walk):
values_calculation["path"] = variable.path values_calculation["path"] = variable.path
return values_calculation 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: def get_path_from_variable(self, values, version: str, path: str) -> str:
variable_path = values.variable variable_path = values.variable
paths = self.objectspace.paths paths = self.objectspace.paths