diff --git a/src/rougail/annotator/property.py b/src/rougail/annotator/property.py index cb834b6e5..ce2cc955e 100644 --- a/src/rougail/annotator/property.py +++ b/src/rougail/annotator/property.py @@ -25,11 +25,13 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . """ -from typing import Union +from typing import Union, List +from tiramisu.setting import PROPERTIES_MAKE_SENSE from rougail.i18n import _ from rougail.error import DictConsistencyError from rougail.annotator.variable import Walk from rougail.convert.object_model import Calculation +from rougail.utils import NAME_REGEXP PROPERTIES = ( @@ -141,6 +143,32 @@ class Annotator(Walk): self.objectspace.properties.add(path, "notunique", True) if variable.auto_save: self.objectspace.properties.add(path, "force_store_value", True) + if variable.tags: + for tag in variable.tags: + self.check_tag(tag, variable.xmlfiles) + self.objectspace.properties.add(variable.path, tag, True) + self.objectspace.informations.add(variable.path, "tags", tuple(variable.tags)) + + def check_tag(self, + tag: str, + xmlfiles: List[str], + ): + match = NAME_REGEXP.search(tag) + if not match: + msg = _( + 'invalid tag name "{0}" should only contains lowercase ascii character, number or _' + ).format(tag) + raise DictConsistencyError(msg, 82, xmlfiles) + if tag in self.objectspace.modes_level: + msg = _( + 'invalid tag name "{0}" should not be a name of an existing mode' + ).format(tag) + raise DictConsistencyError(msg, 82, xmlfiles) + if tag in PROPERTIES_MAKE_SENSE: + msg = _( + 'invalid tag name "{0}" should not be name of an available proprerties' + ).format(tag) + raise DictConsistencyError(msg, 82, xmlfiles) def _convert_property( self, diff --git a/src/rougail/convert/object_model.py b/src/rougail/convert/object_model.py index c71b7b1d6..93fc74db8 100644 --- a/src/rougail/convert/object_model.py +++ b/src/rougail/convert/object_model.py @@ -1013,6 +1013,7 @@ class Variable(BaseModel): description: Optional[str] = None help: Optional[str] = None mode: Optional[str] = None + tags: Optional[list] = None examples: Optional[list] = None test: Optional[list] = None # validations diff --git a/tests/dictionaries/02_0tags/makedict/after.json b/tests/dictionaries/02_0tags/makedict/after.json new file mode 100644 index 000000000..7ea9435a0 --- /dev/null +++ b/tests/dictionaries/02_0tags/makedict/after.json @@ -0,0 +1,10 @@ +{ + "rougail.var1": { + "owner": "default", + "value": null + }, + "rougail.var2": { + "owner": "default", + "value": null + } +} diff --git a/tests/dictionaries/02_0tags/makedict/base.json b/tests/dictionaries/02_0tags/makedict/base.json new file mode 100644 index 000000000..559aec2a4 --- /dev/null +++ b/tests/dictionaries/02_0tags/makedict/base.json @@ -0,0 +1,4 @@ +{ + "rougail.var1": null, + "rougail.var2": null +} diff --git a/tests/dictionaries/02_0tags/makedict/before.json b/tests/dictionaries/02_0tags/makedict/before.json new file mode 100644 index 000000000..7ea9435a0 --- /dev/null +++ b/tests/dictionaries/02_0tags/makedict/before.json @@ -0,0 +1,10 @@ +{ + "rougail.var1": { + "owner": "default", + "value": null + }, + "rougail.var2": { + "owner": "default", + "value": null + } +} diff --git a/tests/dictionaries/02_0tags/makedict/mandatory.json b/tests/dictionaries/02_0tags/makedict/mandatory.json new file mode 100644 index 000000000..8c67ac5f8 --- /dev/null +++ b/tests/dictionaries/02_0tags/makedict/mandatory.json @@ -0,0 +1 @@ +["rougail.var1", "rougail.var2"] \ No newline at end of file diff --git a/tests/dictionaries/02_0tags/makedict/read_write.json b/tests/dictionaries/02_0tags/makedict/read_write.json new file mode 100644 index 000000000..559aec2a4 --- /dev/null +++ b/tests/dictionaries/02_0tags/makedict/read_write.json @@ -0,0 +1,4 @@ +{ + "rougail.var1": null, + "rougail.var2": null +} diff --git a/tests/dictionaries/02_0tags/tiramisu/base.py b/tests/dictionaries/02_0tags/tiramisu/base.py new file mode 100644 index 000000000..5b4fa7f9e --- /dev/null +++ b/tests/dictionaries/02_0tags/tiramisu/base.py @@ -0,0 +1,16 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_2 = StrOption(name="var1", doc="the first variable", properties=frozenset({"basic", "mandatory", "one_tag"}), informations={'ymlfiles': ['../rougail-tests/structures/02_0tags/rougail/00-base.yml'], 'type': 'string', 'tags': ('one_tag',)}) +option_3 = StrOption(name="var2", doc="the second variable", properties=frozenset({"basic", "mandatory", "one_tag", "second_tag"}), informations={'ymlfiles': ['../rougail-tests/structures/02_0tags/rougail/00-base.yml'], 'type': 'string', 'tags': ('one_tag', 'second_tag')}) +optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3], properties=frozenset({"basic"}), informations={'ymlfiles': ['']}) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/02_0tags/tiramisu/no_namespace.py b/tests/dictionaries/02_0tags/tiramisu/no_namespace.py new file mode 100644 index 000000000..6393ffa7a --- /dev/null +++ b/tests/dictionaries/02_0tags/tiramisu/no_namespace.py @@ -0,0 +1,11 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_1 = StrOption(name="var1", doc="the first variable", properties=frozenset({"basic", "mandatory", "one_tag"}), informations={'ymlfiles': ['../rougail-tests/structures/02_0tags/rougail/00-base.yml'], 'type': 'string', 'tags': ('one_tag',)}) +option_2 = StrOption(name="var2", doc="the second variable", properties=frozenset({"basic", "mandatory", "one_tag", "second_tag"}), informations={'ymlfiles': ['../rougail-tests/structures/02_0tags/rougail/00-base.yml'], 'type': 'string', 'tags': ('one_tag', 'second_tag')}) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2]) diff --git a/tests/errors/02_0tags_basic/errno_82 b/tests/errors/02_0tags_basic/errno_82 new file mode 100644 index 000000000..e69de29bb diff --git a/tests/errors/02_0tags_basic/rougail/00-base.yml b/tests/errors/02_0tags_basic/rougail/00-base.yml new file mode 100644 index 000000000..196a9f765 --- /dev/null +++ b/tests/errors/02_0tags_basic/rougail/00-base.yml @@ -0,0 +1,9 @@ +%YAML 1.2 +--- +version: 1.1 + +var1: + description: the first variable + tags: + - basic +... diff --git a/tests/errors/02_0tags_hidden/errno_82 b/tests/errors/02_0tags_hidden/errno_82 new file mode 100644 index 000000000..e69de29bb diff --git a/tests/errors/02_0tags_hidden/rougail/00-base.yml b/tests/errors/02_0tags_hidden/rougail/00-base.yml new file mode 100644 index 000000000..3ddae08e6 --- /dev/null +++ b/tests/errors/02_0tags_hidden/rougail/00-base.yml @@ -0,0 +1,9 @@ +%YAML 1.2 +--- +version: 1.1 + +var1: + description: the first variable + tags: + - hidden +... diff --git a/tests/errors/02_0tags_invalid_name/errno_82 b/tests/errors/02_0tags_invalid_name/errno_82 new file mode 100644 index 000000000..e69de29bb diff --git a/tests/errors/02_0tags_invalid_name/rougail/00-base.yml b/tests/errors/02_0tags_invalid_name/rougail/00-base.yml new file mode 100644 index 000000000..abf32f6d7 --- /dev/null +++ b/tests/errors/02_0tags_invalid_name/rougail/00-base.yml @@ -0,0 +1,9 @@ +%YAML 1.2 +--- +version: 1.1 + +var1: + description: the first variable + tags: + - UnValid Tag +... diff --git a/tests/test_1_flattener.py b/tests/test_1_flattener.py index beea1cea0..0dae1b4d9 100644 --- a/tests/test_1_flattener.py +++ b/tests/test_1_flattener.py @@ -47,7 +47,7 @@ excludes = set([ ]) test_ok -= excludes test_raise -= excludes -#test_ok = ['60_0family_dynamic_source_hidden'] +# test_ok = ['02_0tags'] #test_ok = [] # test_raise = ['80unknown_default_variable_inside_dynamic_family'] #test_raise = []