feat: multi layers support

This commit is contained in:
egarette@silique.fr 2026-05-04 08:18:14 +02:00
parent ef58253dff
commit 338d1d1aae
36 changed files with 253 additions and 110 deletions

View file

@ -18,21 +18,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
from ruamel.yaml import YAML
from pathlib import Path
from itertools import chain
from rougail.error import ExtensionError
from tiramisu.error import ValueOptionError, PropertiesOptionError, LeadershipError
from rougail.utils import undefined
from tiramisu import MetaConfig
from .i18n import _
from .__version__ import __version__
class RougailUserDataYaml:
has_several_layers = True
def __init__(
self,
config,
*,
rougailconfig=None,
**kwargs,
) -> None:
if rougailconfig is None:
from rougail import RougailConfig
@ -46,13 +51,23 @@ class RougailUserDataYaml:
if "yaml" not in user_data:
raise ExtensionError(_("yaml is not set in step.user_data"))
self.rougailconfig = rougailconfig
self.filenames = self.rougailconfig["yaml.filename"]
self.filenames = []
for filename in self.rougailconfig["yaml.filename"]:
filename = Path(filename)
if filename.is_file():
self.filenames.append(filename)
else:
for name in sorted(chain(filename.glob('*.yml'), filename.glob('*.yaml'))):
self.filenames.append(name)
self.file_with_secrets = self.rougailconfig["yaml.file_with_secrets"]
self.config = config
self.errors = []
self.warnings = []
self.source = _('the YAML file "{0}"')
def count_layers(self):
return len(self.filenames)
def run(
self,
) -> None:
@ -61,48 +76,42 @@ class RougailUserDataYaml:
if self.file_with_secrets == "last":
last_filename_idx = len(self.filenames) - 1
for idx, filename in enumerate(self.filenames):
filename = Path(filename)
if filename.is_file():
filenames = [filename]
else:
filenames = list(filename.glob('*.yml')) + list(filename.glob('*.yaml'))
for filename in sorted(filenames):
file_values = self.open(filename)
if not file_values:
continue
values = {}
if not isinstance(file_values, dict):
self.errors.append(
_(
'cannot load "{0}", the root value is not a dict but "{1}"'
).format(filename, file_values)
)
else:
self.parse(
values,
"",
file_values,
filename,
)
if self.file_with_secrets == "none":
allow_secrets_variables = False
elif self.file_with_secrets == "first":
allow_secrets_variables = idx == 0
elif self.file_with_secrets == "last":
allow_secrets_variables = idx == last_filename_idx
else:
allow_secrets_variables = True
user_data.append(
{
"source": self.source.format(filename),
"errors": self.errors,
"warnings": self.warnings,
"values": values,
"options": {
"allow_secrets_variables": allow_secrets_variables,
},
}
file_values = self.open(filename)
if not file_values:
continue
values = {}
if not isinstance(file_values, dict):
self.errors.append(
_(
'cannot load "{0}", the root value is not a dict but "{1}"'
).format(filename, file_values)
)
else:
self.parse(
values,
"",
file_values,
filename,
)
if self.file_with_secrets == "none":
allow_secrets_variables = False
elif self.file_with_secrets == "first":
allow_secrets_variables = idx == 0
elif self.file_with_secrets == "last":
allow_secrets_variables = idx == last_filename_idx
else:
allow_secrets_variables = True
user_data.append(
{
"source": self.source.format(filename),
"errors": self.errors,
"warnings": self.warnings,
"values": values,
"options": {
"allow_secrets_variables": allow_secrets_variables,
},
}
)
return user_data
def open(self, filename: str) -> dict:

View file

@ -1,4 +1,19 @@
{
"errors": [],
"warnings": []
"warnings": [
[
[
"family \"family_disabled\" has property disabled, so cannot access to \"variable1\", it will be ignored when loading from the YAML file \"/home/gnunux/git/stove/rougail-user-data-yaml/tests/errors/yaml/01_disabled_family.yaml\"",
"family_disabled.variable1",
null
]
],
[
[
"family \"family_disabled\" has property disabled, so cannot access to \"variable2\", it will be ignored when loading from the YAML file \"/home/gnunux/git/stove/rougail-user-data-yaml/tests/errors/yaml/01_disabled_family.yaml\"",
"family_disabled.variable2",
null
]
]
]
}

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"variable1\" because is frozen, it will be ignored when loading from the YAML file \"/home/gnunux/git/stove/rougail-user-data-yaml/tests/errors/yaml/02_disabled_hidden_family.yaml\"",
"family \"family_disabled_hidden\" has property disabled and hidden, so cannot access to \"variable1\", it will be ignored when loading from the YAML file \"/home/gnunux/git/stove/rougail-user-data-yaml/tests/errors/yaml/02_disabled_hidden_family.yaml\"",
"family_disabled_hidden.variable1",
null
]

View file

@ -1,4 +1,26 @@
{
"errors": [],
"warnings": []
"warnings": [
[
[
"family \"manual\" (Manual proxy configuration) has property disabled, so cannot access to \"address\" (HTTP address), it will be ignored when loading from the YAML file \"../rougail-tutorials_builder/examples/050/config/02/config.yml\"",
"manual.http_proxy.address",
null
]
],
[
[
"family \"manual\" (Manual proxy configuration) has property disabled, so cannot access to \"port\" (HTTP Port), it will be ignored when loading from the YAML file \"../rougail-tutorials_builder/examples/050/config/02/config.yml\"",
"manual.http_proxy.port",
null
]
],
[
[
"family \"manual\" (Manual proxy configuration) has property disabled, so cannot access to \"use_for_https\" (Also use this proxy for HTTPS), it will be ignored when loading from the YAML file \"../rougail-tutorials_builder/examples/050/config/02/config.yml\"",
"manual.use_for_https",
null
]
]
]
}

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"address\" (HTTPS address) because is frozen, it will be ignored when loading from the YAML file \"../rougail-tutorials_builder/examples/052/config/01/config.yml\"",
"family \"https_proxy\" (HTTPS Proxy) has property hidden, so cannot access to \"address\" (HTTPS address), it will be ignored when loading from the YAML file \"../rougail-tutorials_builder/examples/052/config/01/config.yml\"",
"manual.https_proxy.address",
null
]

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"address\" (HTTPS address) because is frozen, it will be ignored when loading from the YAML file \"../rougail-tutorials_builder/examples/070/config/02/config.yml\"",
"family \"https_proxy\" (HTTPS Proxy) has property hidden, so cannot access to \"address\" (HTTPS address), it will be ignored when loading from the YAML file \"../rougail-tutorials_builder/examples/070/config/02/config.yml\"",
"manual.https_proxy.address",
null
]

View file

@ -1,9 +1,10 @@
[
[
[
"mandatory variable but has no value",
"manual.socks_proxy.address",
null
]
]
]
{
"proxy_mode": "Manual proxy configuration",
"manual.http_proxy.address": "http.proxy.net",
"manual.http_proxy.port": "3128",
"manual.use_for_https": false,
"manual.https_proxy.address": "https.proxy.net",
"manual.https_proxy.port": "8080",
"manual.socks_proxy.address": "socks.proxy.net",
"manual.socks_proxy.port": "8080"
}

View file

@ -1,9 +1,10 @@
[
[
[
"mandatory variable but has no value",
"manual.socks_proxy.address",
null
]
]
]
{
"proxy_mode": "Manual proxy configuration",
"manual.http_proxy.address": "http.proxy.net",
"manual.http_proxy.port": "3128",
"manual.use_for_https": false,
"manual.https_proxy.address": "https.proxy.net",
"manual.https_proxy.port": "8080",
"manual.socks_proxy.address": "socks.proxy.net",
"manual.socks_proxy.port": "8080"
}

View file

@ -4,8 +4,8 @@
"manual.http_proxy.port": "3128",
"manual.use_for_https": false,
"manual.https_proxy.address": "https.proxy.net",
"manual.https_proxy.port": "3128",
"manual.socks_proxy.address": "http.proxy.net",
"manual.socks_proxy.port": "3128",
"manual.https_proxy.port": "8080",
"manual.socks_proxy.address": "socks.proxy.net",
"manual.socks_proxy.port": "8080",
"manual.socks_proxy.version": "v5"
}

View file

@ -4,8 +4,8 @@
"manual.http_proxy.port": "3128",
"manual.use_for_https": false,
"manual.https_proxy.address": "https.proxy.net",
"manual.https_proxy.port": "3128",
"manual.socks_proxy.address": "http.proxy.net",
"manual.socks_proxy.port": "3128",
"manual.https_proxy.port": "8080",
"manual.socks_proxy.address": "socks.proxy.net",
"manual.socks_proxy.port": "8080",
"manual.socks_proxy.version": "v5"
}

View file

@ -0,0 +1,11 @@
{
"proxy_mode": "Manual proxy configuration",
"manual.http_proxy.address": "http.proxy.net",
"manual.http_proxy.port": "3128",
"manual.use_for_https": false,
"manual.https_proxy.address": "https.proxy.net",
"manual.https_proxy.port": "3128",
"manual.socks_proxy.address": "http.proxy.net",
"manual.socks_proxy.port": "3128",
"manual.socks_proxy.version": "v5"
}

View file

@ -0,0 +1,11 @@
{
"proxy_mode": "Manual proxy configuration",
"manual.http_proxy.address": "http.proxy.net",
"manual.http_proxy.port": "3128",
"manual.use_for_https": false,
"manual.https_proxy.address": "https.proxy.net",
"manual.https_proxy.port": "3128",
"manual.socks_proxy.address": "http.proxy.net",
"manual.socks_proxy.port": "3128",
"manual.socks_proxy.version": "v5"
}

View file

@ -0,0 +1,4 @@
{
"errors": [],
"warnings": []
}

View file

@ -0,0 +1,11 @@
{
"proxy_mode": "Manual proxy configuration",
"manual.http_proxy.address": "http.proxy.net",
"manual.http_proxy.port": "3128",
"manual.use_for_https": false,
"manual.https_proxy.address": "https.proxy.net",
"manual.https_proxy.port": "3128",
"manual.socks_proxy.address": "http.proxy.net",
"manual.socks_proxy.port": "3128",
"manual.socks_proxy.version": "v5"
}

View file

@ -0,0 +1,11 @@
{
"proxy_mode": "Manual proxy configuration",
"manual.http_proxy.address": "http.proxy.net",
"manual.http_proxy.port": "3128",
"manual.use_for_https": false,
"manual.https_proxy.address": "https.proxy.net",
"manual.https_proxy.port": "3128",
"manual.socks_proxy.address": "http.proxy.net",
"manual.socks_proxy.port": "3128",
"manual.socks_proxy.version": "v5"
}

View file

@ -0,0 +1,4 @@
{
"errors": [],
"warnings": []
}

View file

@ -3,14 +3,14 @@
"warnings": [
[
[
"cannot modify the option \"var1\" (a first variable) because is frozen, it will be ignored when loading from the YAML file \"tests/results/00_2default_calculated_params_permissive/file/all.yml\"",
"family \"leadership\" has property hidden, so cannot access to \"var1\" (a first variable), it will be ignored when loading from the YAML file \"tests/results/00_2default_calculated_params_permissive/file/all.yml\"",
"rougail.leadership.var1",
null
]
],
[
[
"cannot modify the option \"var2\" (a first variable) at index \"0\" because is frozen, it will be ignored when loading from the YAML file \"tests/results/00_2default_calculated_params_permissive/file/all.yml\"",
"family \"leadership\" is hidden, \"var2\" (a first variable) at index \"0\", it will be ignored when loading from the YAML file \"tests/results/00_2default_calculated_params_permissive/file/all.yml\"",
"rougail.leadership.var2",
null
]

View file

@ -1,12 +0,0 @@
{
"errors": [],
"warnings": [
[
[
"family \"condition\" (a condition) has property disabled, so cannot access to \"variable\" (a variable), it will be ignored when loading from the YAML file \"tests/results/04_5disabled_calculation_variable11/file/mandatories.yml\"",
"rougail.variable",
null
]
]
]
}

View file

@ -1,4 +1,12 @@
{
"errors": [],
"warnings": []
"warnings": [
[
[
"family \"family\" has property disabled, so cannot access to \"var1\", it will be ignored when loading from the YAML file \"tests/results/16_2family_redefine_calculation/file/all.yml\"",
"rougail.family.var1",
null
]
]
]
}

View file

@ -1,4 +1,12 @@
{
"errors": [],
"warnings": []
"warnings": [
[
[
"family \"family\" has property disabled, so cannot access to \"var1\", it will be ignored when loading from the YAML file \"tests/results/16_2family_redefine_calculation/file/mandatories.yml\"",
"rougail.family.var1",
null
]
]
]
}

View file

@ -1,4 +1,12 @@
{
"errors": [],
"warnings": []
"warnings": [
[
[
"family \"family\" has property disabled, so cannot access to \"var1\", it will be ignored when loading from the YAML file \"tests/results/16_2family_redefine_disabled/file/all.yml\"",
"rougail.family.var1",
null
]
]
]
}

View file

@ -1,4 +1,12 @@
{
"errors": [],
"warnings": []
"warnings": [
[
[
"family \"family\" has property disabled, so cannot access to \"var1\", it will be ignored when loading from the YAML file \"tests/results/16_2family_redefine_disabled/file/mandatories.yml\"",
"rougail.family.var1",
null
]
]
]
}

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"leader\" (a leader) because is frozen, it will be ignored when loading from the YAML file \"tests/results/17_5redefine_leadership/file/all.yml\"",
"family \"leader\" (a leadership) has property hidden, so cannot access to \"leader\" (a leader), it will be ignored when loading from the YAML file \"tests/results/17_5redefine_leadership/file/all.yml\"",
"rougail.leader.leader",
null
]

View file

@ -3,42 +3,42 @@
"warnings": [
[
[
"cannot modify the option \"my_variable\" because is frozen, it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"family \"my_family\" (This is a great family) has property disabled and hidden, so cannot access to \"my_variable\", it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"rougail.my_family.type.my_variable",
null
]
],
[
[
"cannot modify the option \"my_variable\" because is frozen, it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"family \"my_family\" (This is a great family) has property disabled and hidden, so cannot access to \"my_variable\", it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"rougail.my_family.description.my_variable",
null
]
],
[
[
"cannot modify the option \"my_variable\" because is frozen, it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"family \"my_family\" (This is a great family) has property disabled and hidden, so cannot access to \"my_variable\", it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"rougail.my_family.help.my_variable",
null
]
],
[
[
"cannot modify the option \"my_variable\" because is frozen, it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"family \"my_family\" (This is a great family) has property disabled and hidden, so cannot access to \"my_variable\", it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"rougail.my_family.mode.my_variable",
null
]
],
[
[
"cannot modify the option \"my_variable\" because is frozen, it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"family \"my_family\" (This is a great family) has property disabled and hidden, so cannot access to \"my_variable\", it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"rougail.my_family.hidden.my_variable",
null
]
],
[
[
"cannot modify the option \"my_variable\" because is frozen, it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"family \"my_family\" (This is a great family) has property disabled and hidden, so cannot access to \"my_variable\", it will be ignored when loading from the YAML file \"tests/results/20_0family_underscore/file/all.yml\"",
"rougail.my_family.disabled.my_variable",
null
]

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"var1\" (a variable) because is frozen, it will be ignored when loading from the YAML file \"tests/results/24_0family_hidden_condition_variable_sub_family/file/all.yml\"",
"family \"family\" (possibly hidden family) has property hidden, so cannot access to \"var1\" (a variable), it will be ignored when loading from the YAML file \"tests/results/24_0family_hidden_condition_variable_sub_family/file/all.yml\"",
"rougail.family.subfamily.var1",
null
]

View file

@ -3,7 +3,14 @@
"warnings": [
[
[
"unable to carry out a calculation for \"var2\" (A description), cannot access to optiondescription \"family\" because has property \"disabled\" in \"/home/gnunux/git/stove/rougail-tests/structures/24_family_disabled_var_hidden/rougail/00-base.yml\", it will be ignored when loading from the YAML file \"tests/results/24_family_disabled_var_hidden/file/all.yml\"",
"family \"family\" has property disabled, so cannot access to \"var1\" (A description), it will be ignored when loading from the YAML file \"tests/results/24_family_disabled_var_hidden/file/all.yml\"",
"rougail.family.var1",
null
]
],
[
[
"family \"family\" has property disabled, so cannot access to \"var2\" (A description), it will be ignored when loading from the YAML file \"tests/results/24_family_disabled_var_hidden/file/all.yml\"",
"rougail.family.var2",
null
]

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"unable to carry out a calculation for \"var2\" (A description), cannot access to optiondescription \"family\" because has property \"disabled\" in \"/home/gnunux/git/stove/rougail-tests/structures/24_family_disabled_var_hidden/rougail/00-base.yml\", it will be ignored when loading from the YAML file \"tests/results/24_family_disabled_var_hidden/file/mandatories.yml\"",
"family \"family\" has property disabled, so cannot access to \"var2\" (A description), it will be ignored when loading from the YAML file \"tests/results/24_family_disabled_var_hidden/file/mandatories.yml\"",
"rougail.family.var2",
null
]

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"leader\" (a leader) because is frozen, it will be ignored when loading from the YAML file \"tests/results/44_0leadership_hidden/file/all.yml\"",
"family \"leader\" (a leadership) has property hidden, so cannot access to \"leader\" (a leader), it will be ignored when loading from the YAML file \"tests/results/44_0leadership_hidden/file/all.yml\"",
"rougail.leader.leader",
null
]

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"leader\" (a leader) because is frozen, it will be ignored when loading from the YAML file \"tests/results/44_0leadership_leader_hidden/file/all.yml\"",
"family \"leader\" (a leadership) has property hidden, so cannot access to \"leader\" (a leader), it will be ignored when loading from the YAML file \"tests/results/44_0leadership_leader_hidden/file/all.yml\"",
"rougail.leader.leader",
null
]

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"leader\" (a leader) because is frozen, it will be ignored when loading from the YAML file \"tests/results/44_1leadership_append_hidden_follower/file/all.yml\"",
"family \"leader\" (a leadership) has property hidden, so cannot access to \"leader\" (a leader), it will be ignored when loading from the YAML file \"tests/results/44_1leadership_append_hidden_follower/file/all.yml\"",
"rougail.leader.leader",
null
]

View file

@ -3,7 +3,7 @@
"warnings": [
[
[
"cannot modify the option \"var\" (a variable) because is frozen, it will be ignored when loading from the YAML file \"tests/results/60_0family_hidden/file/all.yml\"",
"family \"family\" (a family) has property hidden, so cannot access to \"var\" (a variable), it will be ignored when loading from the YAML file \"tests/results/60_0family_hidden/file/all.yml\"",
"rougail.family.var",
null
]

View file

@ -1,4 +1,12 @@
{
"errors": [],
"warnings": []
"warnings": [
[
[
"variable has property hidden, it will be ignored when loading from the YAML file \"tests/results/60_5family_dynamic_calc_identifier/file/all.yml\"",
"rougail.var2",
null
]
]
]
}

View file

@ -3,7 +3,7 @@
"val1",
"val2"
],
"rougail.var2": "string1",
"rougail.var2": "val1",
"rougail.dynval1.var": "string1",
"rougail.dynval2.var": "string1",
"rougail.var3": "string1"

View file

@ -1,4 +1,12 @@
{
"errors": [],
"warnings": []
"warnings": [
[
[
"variable has property hidden, it will be ignored when loading from the YAML file \"tests/results/60_5family_dynamic_calc_identifier_multi/file/all.yml\"",
"rougail.var2",
null
]
]
]
}

View file

@ -3,7 +3,7 @@
"val1",
"val2"
],
"rougail.var2": "string1",
"rougail.var2": "val1",
"rougail.dynval1.var": [
"string1",
"string2",

View file

@ -3,14 +3,14 @@
"warnings": [
[
[
"cannot modify the option \"var\" (a variable) because is frozen, it will be ignored when loading from the YAML file \"tests/results/60_5family_dynamic_hidden_suffix/file/all.yml\"",
"family \"dynval2\" (a dynamic family) has property hidden, so cannot access to \"var\" (a variable), it will be ignored when loading from the YAML file \"tests/results/60_5family_dynamic_hidden_suffix/file/all.yml\"",
"rougail.dynval2.var",
null
]
],
[
[
"cannot modify the option \"var\" (a new variable) because is frozen, it will be ignored when loading from the YAML file \"tests/results/60_5family_dynamic_hidden_suffix/file/all.yml\"",
"family \"dynval2\" (a dynamic family) has property hidden, so cannot access to \"var\" (a new variable), it will be ignored when loading from the YAML file \"tests/results/60_5family_dynamic_hidden_suffix/file/all.yml\"",
"rougail.dynval2.family.var",
null
]