allow 'variable' in dynamic family in 1.1

This commit is contained in:
egarette@silique.fr 2024-07-06 15:16:20 +02:00
parent 8b52232d6a
commit d1db967dd5
2 changed files with 5 additions and 5 deletions

View file

@ -467,7 +467,7 @@ class ParserVariable:
return return
family_obj = {} family_obj = {}
subfamily_obj = {} subfamily_obj = {}
force_to_attrs = list(self.list_attributes(obj)) force_to_attrs = list(self.list_attributes(obj, version))
for key, value in obj.items(): for key, value in obj.items():
if key in force_to_attrs: if key in force_to_attrs:
if key.startswith("_"): if key.startswith("_"):
@ -545,6 +545,7 @@ class ParserVariable:
def list_attributes( def list_attributes(
self, self,
obj: Dict[str, Any], obj: Dict[str, Any],
version: str,
) -> Iterator[str]: ) -> Iterator[str]:
"""List attributes""" """List attributes"""
force_to_variable = [] force_to_variable = []
@ -567,8 +568,7 @@ class ParserVariable:
): ):
# it's a dict, so a new variables! # it's a dict, so a new variables!
continue continue
# FIXME should be remove with 1.0 format if version == '1.0' and key == "variable" and obj.get("type") != "dynamic" and obj.get("_type") != "dynamic":
if key == "variable" and obj.get("type") != "dynamic":
continue continue
if key in self.family_attrs: if key in self.family_attrs:
yield key yield key
@ -595,13 +595,14 @@ class ParserVariable:
raise DictConsistencyError(f'dynamic family must have "variable" attribute for "{path}"', 101, family["xmlfiles"]) raise DictConsistencyError(f'dynamic family must have "variable" attribute for "{path}"', 101, family["xmlfiles"])
if 'dynamic' in family: if 'dynamic' in family:
raise DictConsistencyError('variable and dynamic cannot be set together in the dynamic family "{path}"', 100, family['xmlfiles']) raise DictConsistencyError('variable and dynamic cannot be set together in the dynamic family "{path}"', 100, family['xmlfiles'])
#FIXME compatibility to 1.0
if "variable" in family:
family['dynamic'] = {'type': 'variable', family['dynamic'] = {'type': 'variable',
'variable': family['variable'], 'variable': family['variable'],
'propertyerror': False, 'propertyerror': False,
'allow_none': True, 'allow_none': True,
} }
del family['variable'] del family['variable']
#FIXME only for 1.0
if "variable" in family: if "variable" in family:
raise Exception(f'dynamic family must not have "variable" attribute for "{family["path"]}" in {family["xmlfiles"]}') raise Exception(f'dynamic family must not have "variable" attribute for "{family["path"]}" in {family["xmlfiles"]}')
else: else:

View file

@ -36,7 +36,6 @@ except ModuleNotFoundError as err:
# from ast import parse as ast_parse # from ast import parse as ast_parse
from json import dumps from json import dumps
from ruamel.yaml import YAML from ruamel.yaml import YAML
from yaml import dump, SafeDumper
from pathlib import Path from pathlib import Path
from .i18n import _ from .i18n import _