feat: add tags support
This commit is contained in:
parent
e42347cf3d
commit
192325e9e0
16 changed files with 114 additions and 2 deletions
|
|
@ -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/>.
|
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.i18n import _
|
||||||
from rougail.error import DictConsistencyError
|
from rougail.error import DictConsistencyError
|
||||||
from rougail.annotator.variable import Walk
|
from rougail.annotator.variable import Walk
|
||||||
from rougail.convert.object_model import Calculation
|
from rougail.convert.object_model import Calculation
|
||||||
|
from rougail.utils import NAME_REGEXP
|
||||||
|
|
||||||
|
|
||||||
PROPERTIES = (
|
PROPERTIES = (
|
||||||
|
|
@ -141,6 +143,32 @@ class Annotator(Walk):
|
||||||
self.objectspace.properties.add(path, "notunique", True)
|
self.objectspace.properties.add(path, "notunique", True)
|
||||||
if variable.auto_save:
|
if variable.auto_save:
|
||||||
self.objectspace.properties.add(path, "force_store_value", True)
|
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(
|
def _convert_property(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -1013,6 +1013,7 @@ class Variable(BaseModel):
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
help: Optional[str] = None
|
help: Optional[str] = None
|
||||||
mode: Optional[str] = None
|
mode: Optional[str] = None
|
||||||
|
tags: Optional[list] = None
|
||||||
examples: Optional[list] = None
|
examples: Optional[list] = None
|
||||||
test: Optional[list] = None
|
test: Optional[list] = None
|
||||||
# validations
|
# validations
|
||||||
|
|
|
||||||
10
tests/dictionaries/02_0tags/makedict/after.json
Normal file
10
tests/dictionaries/02_0tags/makedict/after.json
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.var1": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"rougail.var2": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
||||||
4
tests/dictionaries/02_0tags/makedict/base.json
Normal file
4
tests/dictionaries/02_0tags/makedict/base.json
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.var1": null,
|
||||||
|
"rougail.var2": null
|
||||||
|
}
|
||||||
10
tests/dictionaries/02_0tags/makedict/before.json
Normal file
10
tests/dictionaries/02_0tags/makedict/before.json
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.var1": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"rougail.var2": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/dictionaries/02_0tags/makedict/mandatory.json
Normal file
1
tests/dictionaries/02_0tags/makedict/mandatory.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.var1", "rougail.var2"]
|
||||||
4
tests/dictionaries/02_0tags/makedict/read_write.json
Normal file
4
tests/dictionaries/02_0tags/makedict/read_write.json
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.var1": null,
|
||||||
|
"rougail.var2": null
|
||||||
|
}
|
||||||
16
tests/dictionaries/02_0tags/tiramisu/base.py
Normal file
16
tests/dictionaries/02_0tags/tiramisu/base.py
Normal 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])
|
||||||
11
tests/dictionaries/02_0tags/tiramisu/no_namespace.py
Normal file
11
tests/dictionaries/02_0tags/tiramisu/no_namespace.py
Normal 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])
|
||||||
0
tests/errors/02_0tags_basic/errno_82
Normal file
0
tests/errors/02_0tags_basic/errno_82
Normal file
9
tests/errors/02_0tags_basic/rougail/00-base.yml
Normal file
9
tests/errors/02_0tags_basic/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
var1:
|
||||||
|
description: the first variable
|
||||||
|
tags:
|
||||||
|
- basic
|
||||||
|
...
|
||||||
0
tests/errors/02_0tags_hidden/errno_82
Normal file
0
tests/errors/02_0tags_hidden/errno_82
Normal file
9
tests/errors/02_0tags_hidden/rougail/00-base.yml
Normal file
9
tests/errors/02_0tags_hidden/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
var1:
|
||||||
|
description: the first variable
|
||||||
|
tags:
|
||||||
|
- hidden
|
||||||
|
...
|
||||||
0
tests/errors/02_0tags_invalid_name/errno_82
Normal file
0
tests/errors/02_0tags_invalid_name/errno_82
Normal file
9
tests/errors/02_0tags_invalid_name/rougail/00-base.yml
Normal file
9
tests/errors/02_0tags_invalid_name/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
var1:
|
||||||
|
description: the first variable
|
||||||
|
tags:
|
||||||
|
- UnValid Tag
|
||||||
|
...
|
||||||
|
|
@ -47,7 +47,7 @@ excludes = set([
|
||||||
])
|
])
|
||||||
test_ok -= excludes
|
test_ok -= excludes
|
||||||
test_raise -= excludes
|
test_raise -= excludes
|
||||||
#test_ok = ['60_0family_dynamic_source_hidden']
|
# test_ok = ['02_0tags']
|
||||||
#test_ok = []
|
#test_ok = []
|
||||||
# test_raise = ['80unknown_default_variable_inside_dynamic_family']
|
# test_raise = ['80unknown_default_variable_inside_dynamic_family']
|
||||||
#test_raise = []
|
#test_raise = []
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue