Compare commits
3 commits
8df55289eb
...
b3917cb862
| Author | SHA1 | Date | |
|---|---|---|---|
| b3917cb862 | |||
| a749d66d6e | |||
| 66e6ddfe31 |
13 changed files with 120 additions and 9 deletions
|
|
@ -37,6 +37,7 @@ from .object_model import (
|
||||||
)
|
)
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
from ..error import DictConsistencyError
|
from ..error import DictConsistencyError
|
||||||
|
from ..tiramisu import CONVERT_OPTION
|
||||||
|
|
||||||
|
|
||||||
class CollectFamily:
|
class CollectFamily:
|
||||||
|
|
@ -53,7 +54,7 @@ class CollectFamily:
|
||||||
elif "variable" in self.parameters:
|
elif "variable" in self.parameters:
|
||||||
self.name += "{{ identifier }}"
|
self.name += "{{ identifier }}"
|
||||||
self.path += "{{ identifier }}"
|
self.path += "{{ identifier }}"
|
||||||
elif self.raises:
|
elif self.raises and not self.is_type:
|
||||||
msg = f'dynamic family name must have "{{{{ identifier }}}}" in his name for "{self.path}"'
|
msg = f'dynamic family name must have "{{{{ identifier }}}}" in his name for "{self.path}"'
|
||||||
raise DictConsistencyError(msg, 13, self.sources)
|
raise DictConsistencyError(msg, 13, self.sources)
|
||||||
if self.version == "1.0":
|
if self.version == "1.0":
|
||||||
|
|
@ -197,7 +198,14 @@ class CollectVariable:
|
||||||
)
|
)
|
||||||
new_params = []
|
new_params = []
|
||||||
namespace = self.objectspace.namespace
|
namespace = self.objectspace.namespace
|
||||||
|
params_data = list(CONVERT_OPTION.get(self.user_type, {}).get("params", {}))
|
||||||
for key, val in params.items():
|
for key, val in params.items():
|
||||||
|
if params_data and key not in params_data:
|
||||||
|
raise DictConsistencyError(
|
||||||
|
_('params "{0}" is not a known parameters with type "{1}" for "{2}" (the list of possible parameters is {3})').format(key, self.user_type, self.path, display_list(params_data, add_quote=True)),
|
||||||
|
92,
|
||||||
|
self.sources,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
new_params.append(
|
new_params.append(
|
||||||
AnyParam(
|
AnyParam(
|
||||||
|
|
@ -493,6 +501,7 @@ class Collect(CollectType, CollectFamily, CollectVariable):
|
||||||
parent_option: Optional["Collect"],
|
parent_option: Optional["Collect"],
|
||||||
*,
|
*,
|
||||||
raises: bool = True,
|
raises: bool = True,
|
||||||
|
is_type: bool = False,
|
||||||
test_exists: bool = True,
|
test_exists: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.sources_types = None
|
self.sources_types = None
|
||||||
|
|
@ -503,6 +512,7 @@ class Collect(CollectType, CollectFamily, CollectVariable):
|
||||||
else:
|
else:
|
||||||
path = f"{subpath}.{name}"
|
path = f"{subpath}.{name}"
|
||||||
self.raises = raises
|
self.raises = raises
|
||||||
|
self.is_type = is_type
|
||||||
self.test_exists = test_exists
|
self.test_exists = test_exists
|
||||||
if self.raises and name.startswith("_"):
|
if self.raises and name.startswith("_"):
|
||||||
msg = f'the variable or family "{self.path}" is incorrect, it must not starts with "_" character'
|
msg = f'the variable or family "{self.path}" is incorrect, it must not starts with "_" character'
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,7 @@ class ParserVariable:
|
||||||
obj,
|
obj,
|
||||||
comment,
|
comment,
|
||||||
parent_option,
|
parent_option,
|
||||||
|
is_type=self.loaded_custom_types is not None,
|
||||||
)
|
)
|
||||||
if option.option_type == "family":
|
if option.option_type == "family":
|
||||||
parser = self.parse_family
|
parser = self.parse_family
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ class Walker:
|
||||||
main_structures: Optional[List[str]] = None,
|
main_structures: Optional[List[str]] = None,
|
||||||
isolated_namespace: bool = True,
|
isolated_namespace: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
if not main_namespace:
|
||||||
|
directory_dict = extra_structures.items()
|
||||||
|
else:
|
||||||
directory_dict = chain(
|
directory_dict = chain(
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -632,7 +632,7 @@ class UserData:
|
||||||
default = option.value.default()
|
default = option.value.default()
|
||||||
if option.isleader():
|
if option.isleader():
|
||||||
default = default[0]
|
default = default[0]
|
||||||
value = _('{0} (the search key is "{1}")').format(value, default)
|
value = _('{0} (the key being sought is "{1}")').format(value, default)
|
||||||
option_without_index.information.set(
|
option_without_index.information.set(
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,14 @@ def test_type_dynfamily_namespace():
|
||||||
type_variable("family_dynfamily", namespace=True)
|
type_variable("family_dynfamily", namespace=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_type_root_dynfamily():
|
||||||
|
type_variable("family_root_dynfamily")
|
||||||
|
|
||||||
|
|
||||||
|
def test_type_root_dynfamily_namespace():
|
||||||
|
type_variable("family_root_dynfamily", namespace=True)
|
||||||
|
|
||||||
|
|
||||||
def test_type_family_subfamily_add():
|
def test_type_family_subfamily_add():
|
||||||
type_variable("family_subfamily_add")
|
type_variable("family_subfamily_add")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
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
|
||||||
|
try:
|
||||||
|
groups.namespace
|
||||||
|
except:
|
||||||
|
groups.addgroup('namespace')
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
option_1 = StrOption(name="a_variable", doc="A variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/structures/family_root_dynfamily/00_structure.yml'], 'type': 'string'})
|
||||||
|
option_3 = StrOption(name="a_first_variable", doc="A first variable", default=Calculation(func['calc_value'], Params((ParamIdentifier()))), properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/family_root_dynfamily/00_structure.yml', 'tests/types/structures/family_root_dynfamily/00_structure.yml'], 'type': 'string'})
|
||||||
|
optiondescription_2 = ConvertDynOptionDescription(name="my_family_{{ identifier }}", doc="My family type", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_1)))), children=[option_3], properties=frozenset({"standard"}), informations={'dynamic_variable': 'a_variable', 'ymlfiles': ['tests/types/types/family_root_dynfamily/00_structure.yml', 'tests/types/structures/family_root_dynfamily/00_structure.yml']})
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, optiondescription_2])
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"a_variable": [
|
||||||
|
"val1",
|
||||||
|
"val2"
|
||||||
|
],
|
||||||
|
"my_family_val1.a_first_variable": "val1",
|
||||||
|
"my_family_val2.a_first_variable": "val2"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"a_variable": [
|
||||||
|
"val1",
|
||||||
|
"val2"
|
||||||
|
],
|
||||||
|
"my_family_val1.a_first_variable": "val1",
|
||||||
|
"my_family_val2.a_first_variable": "val2"
|
||||||
|
}
|
||||||
16
tests/types/result/family_root_dynfamily/tiramisu.py
Normal file
16
tests/types/result/family_root_dynfamily/tiramisu.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
|
||||||
|
try:
|
||||||
|
groups.namespace
|
||||||
|
except:
|
||||||
|
groups.addgroup('namespace')
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
option_3 = StrOption(name="a_variable", doc="A variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/structures/family_root_dynfamily/00_structure.yml'], 'type': 'string'})
|
||||||
|
option_5 = StrOption(name="a_first_variable", doc="A first variable", default=Calculation(func['calc_value'], Params((ParamIdentifier()))), properties=frozenset({"mandatory", "standard"}), informations={'ymlfiles': ['tests/types/types/family_root_dynfamily/00_structure.yml', 'tests/types/structures/family_root_dynfamily/00_structure.yml'], 'type': 'string'})
|
||||||
|
optiondescription_4 = ConvertDynOptionDescription(name="my_family_{{ identifier }}", doc="My family type", identifiers=Calculation(func['calc_value'], Params((ParamOption(option_3)))), children=[option_5], properties=frozenset({"standard"}), informations={'dynamic_variable': 'ns2.a_variable', 'ymlfiles': ['tests/types/types/family_root_dynfamily/00_structure.yml', 'tests/types/structures/family_root_dynfamily/00_structure.yml']})
|
||||||
|
optiondescription_2 = OptionDescription(name="ns2", doc="NS2", group_type=groups.namespace, children=[option_3, optiondescription_4], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_2])
|
||||||
8
tests/types/result/family_root_dynfamily/variables.json
Normal file
8
tests/types/result/family_root_dynfamily/variables.json
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"ns2.a_variable": [
|
||||||
|
"val1",
|
||||||
|
"val2"
|
||||||
|
],
|
||||||
|
"ns2.my_family_val1.a_first_variable": "val1",
|
||||||
|
"ns2.my_family_val2.a_first_variable": "val2"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"ns2.a_variable": [
|
||||||
|
"val1",
|
||||||
|
"val2"
|
||||||
|
],
|
||||||
|
"ns2.my_family_val1.a_first_variable": "val1",
|
||||||
|
"ns2.my_family_val2.a_first_variable": "val2"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
a_variable: # A variable
|
||||||
|
- val1
|
||||||
|
- val2
|
||||||
|
|
||||||
|
my_family_{{ identifier }}:
|
||||||
|
type: my_family_type
|
||||||
|
dynamic:
|
||||||
|
variable: _.a_variable
|
||||||
|
...
|
||||||
13
tests/types/types/family_root_dynfamily/00_structure.yml
Normal file
13
tests/types/types/family_root_dynfamily/00_structure.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
my_family_type:
|
||||||
|
description: My family type
|
||||||
|
dynamic: []
|
||||||
|
|
||||||
|
a_first_variable:
|
||||||
|
description: A first variable
|
||||||
|
default:
|
||||||
|
type: identifier
|
||||||
|
...
|
||||||
Loading…
Reference in a new issue