feat: can link regexp variable

This commit is contained in:
egarette@silique.fr 2025-04-01 08:55:00 +02:00
parent dc311466a2
commit 1858eeeb06
10 changed files with 110 additions and 1 deletions

View file

@ -47,6 +47,7 @@ class Annotator(Walk): # pylint: disable=R0903
self.objectspace = objectspace self.objectspace = objectspace
self.convert_value() self.convert_value()
self.valid_choices() self.valid_choices()
self.valid_regexp()
def convert_value(self) -> None: def convert_value(self) -> None:
"""convert value""" """convert value"""
@ -114,7 +115,7 @@ class Annotator(Walk): # pylint: disable=R0903
if isinstance(variable.choices, Calculation): if isinstance(variable.choices, Calculation):
continue continue
if variable.choices is None: if variable.choices is None:
msg = f'the variable "{variable.path}" is a "choice" variable but don\'t have any choice' msg = _(f'the variable "{variable.path}" is a "choice" variable but don\'t have any choice')
raise DictConsistencyError(msg, 19, variable.xmlfiles) raise DictConsistencyError(msg, 19, variable.xmlfiles)
if not variable.mandatory and not variable.multi: if not variable.mandatory and not variable.multi:
self.add_choice_nil(variable) self.add_choice_nil(variable)
@ -125,3 +126,11 @@ class Annotator(Walk): # pylint: disable=R0903
if choice is None: if choice is None:
return return
variable.choices.append(None) variable.choices.append(None)
def valid_regexp(self) -> None:
for variable in self.get_variables():
if variable.type != "regexp":
continue
if variable.regexp is None:
msg = _(f'the variable "{variable.path}" is a "regexp" variable but don\'t have any regexp')
raise DictConsistencyError(msg, 66, variable.xmlfiles)

View file

@ -156,6 +156,8 @@ class Annotator(Walk): # pylint: disable=R0903
variable.params = calculated_variable.params variable.params = calculated_variable.params
if variable.type == 'choice' and variable.choices is None: if variable.type == 'choice' and variable.choices is None:
variable.choices = calculated_variable.choices variable.choices = calculated_variable.choices
if variable.type == 'regexp' and variable.regexp is None:
variable.regexp = calculated_variable.regexp
# copy multi attribut # copy multi attribut
if variable.multi is None: if variable.multi is None:
calculated_path = calculated_variable.path calculated_path = calculated_variable.path

View file

@ -0,0 +1,18 @@
{
"rougail.var1": {
"owner": "default",
"value": [
"a",
"b",
"c"
]
},
"rougail.var2": {
"owner": "default",
"value": "a"
},
"rougail.family.var3": {
"owner": "default",
"value": "a"
}
}

View file

@ -0,0 +1,9 @@
{
"rougail.var1": [
"a",
"b",
"c"
],
"rougail.var2": "a",
"rougail.family.var3": "a"
}

View file

@ -0,0 +1,18 @@
{
"rougail.var1": {
"owner": "default",
"value": [
"a",
"b",
"c"
]
},
"rougail.var2": {
"owner": "default",
"value": "a"
},
"rougail.family.var3": {
"owner": "default",
"value": "a"
}
}

View file

@ -0,0 +1,26 @@
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")
class Regexp_option_2(RegexpOption):
__slots__ = tuple()
_type = 'value'
Regexp_option_2._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$")
class Regexp_option_3(RegexpOption):
__slots__ = tuple()
_type = 'value'
Regexp_option_3._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$")
option_2 = Regexp_option_2(name="var1", doc="a first variable", default="#a1a1a1", properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp', 'test': ('#b1b1b1', '#b2b2b2')})
option_3 = Regexp_option_3(name="var2", doc="a second variable", default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp'})
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3], properties=frozenset({"standard"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,21 @@
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")
class Regexp_option_1(RegexpOption):
__slots__ = tuple()
_type = 'value'
Regexp_option_1._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$")
class Regexp_option_2(RegexpOption):
__slots__ = tuple()
_type = 'value'
Regexp_option_2._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$")
option_1 = Regexp_option_1(name="var1", doc="a first variable", default="#a1a1a1", properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp', 'test': ('#b1b1b1', '#b2b2b2')})
option_2 = Regexp_option_2(name="var2", doc="a second variable", default=Calculation(func['calc_value'], Params((ParamOption(option_1)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp'})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2])

View file

@ -0,0 +1,5 @@
---
version: '1.1'
var:
description: a first variable
type: regexp