feat: add tags support

This commit is contained in:
egarette@silique.fr 2025-10-26 07:47:33 +01:00
parent e42347cf3d
commit 192325e9e0
16 changed files with 114 additions and 2 deletions

View file

@ -25,11 +25,13 @@ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
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,

View file

@ -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

View file

@ -0,0 +1,10 @@
{
"rougail.var1": {
"owner": "default",
"value": null
},
"rougail.var2": {
"owner": "default",
"value": null
}
}

View file

@ -0,0 +1,4 @@
{
"rougail.var1": null,
"rougail.var2": null
}

View file

@ -0,0 +1,10 @@
{
"rougail.var1": {
"owner": "default",
"value": null
},
"rougail.var2": {
"owner": "default",
"value": null
}
}

View file

@ -0,0 +1 @@
["rougail.var1", "rougail.var2"]

View file

@ -0,0 +1,4 @@
{
"rougail.var1": null,
"rougail.var2": null
}

View file

@ -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])

View file

@ -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])

View file

View file

@ -0,0 +1,9 @@
%YAML 1.2
---
version: 1.1
var1:
description: the first variable
tags:
- basic
...

View file

View file

@ -0,0 +1,9 @@
%YAML 1.2
---
version: 1.1
var1:
description: the first variable
tags:
- hidden
...

View file

@ -0,0 +1,9 @@
%YAML 1.2
---
version: 1.1
var1:
description: the first variable
tags:
- UnValid Tag
...

View file

@ -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 = []