diff --git a/src/rougail/__init__.py b/src/rougail/__init__.py index 4d16f9d84..79a63f3de 100644 --- a/src/rougail/__init__.py +++ b/src/rougail/__init__.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/annotator/__init__.py b/src/rougail/annotator/__init__.py index 9111edaa9..451fb20aa 100644 --- a/src/rougail/annotator/__init__.py +++ b/src/rougail/annotator/__init__.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/annotator/family.py b/src/rougail/annotator/family.py index e2cd224f1..b2db5ae7c 100644 --- a/src/rougail/annotator/family.py +++ b/src/rougail/annotator/family.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/annotator/property.py b/src/rougail/annotator/property.py index d21ab07f5..af883c60b 100644 --- a/src/rougail/annotator/property.py +++ b/src/rougail/annotator/property.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/annotator/value.py b/src/rougail/annotator/value.py index 6736c3496..61dceb489 100644 --- a/src/rougail/annotator/value.py +++ b/src/rougail/annotator/value.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/annotator/variable.py b/src/rougail/annotator/variable.py index 08e7d3265..cf99752ac 100644 --- a/src/rougail/annotator/variable.py +++ b/src/rougail/annotator/variable.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/config.py b/src/rougail/config.py index ac66e5fa1..e3174d0fd 100644 --- a/src/rougail/config.py +++ b/src/rougail/config.py @@ -10,7 +10,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the @@ -33,6 +33,7 @@ from tiramisu import Config from ruamel.yaml import YAML from .utils import _, load_modules, normalize_family from .convert import RougailConvert +from .object_model import get_convert_option_types if version_info.major == 3 and version_info.minor: import rougail.structural_commandline.object_model @@ -72,39 +73,52 @@ def get_level(module): class _RougailConfig: - def __init__(self, backward_compatibility: bool, root, extra_vars: dict): + def __init__(self, backward_compatibility: bool, + add_extra_options: bool): self.backward_compatibility = backward_compatibility + self.add_extra_options = add_extra_options + self.root = None + + def copy(self): + rougailconfig = _RougailConfig( + self.backward_compatibility, + self.add_extra_options, + ) + if self.root: + rougailconfig.config.value.importation(self.config.value.exportation()) + rougailconfig.config.property.importation(self.config.property.exportation()) + rougailconfig.config.property.read_only() + rougailconfig.root = self.root + rougailconfig.config = self.config + rougailconfig.extra_vars = self.extra_vars + for variable in self.not_in_tiramisu: + value = getattr(self, variable) + if not isinstance(value, str): + value = value.copy() + setattr(rougailconfig, variable, value) + return rougailconfig + + def generate_config(self): + root, extra_vars = _rougail_config(self.backward_compatibility, self.add_extra_options) self.root = root self.config = Config( self.root, ) - self.config.property.read_only() self.extra_vars = extra_vars self.not_in_tiramisu = NOT_IN_TIRAMISU | extra_vars for variable, default_value in self.not_in_tiramisu.items(): if not isinstance(default_value, str): default_value = default_value.copy() setattr(self, variable, default_value) - - def copy(self): - rougailconfig = _RougailConfig( - self.backward_compatibility, self.root, self.extra_vars - ) - rougailconfig.config.value.importation(self.config.value.exportation()) - rougailconfig.config.property.importation(self.config.property.exportation()) - rougailconfig.config.property.read_only() - for variable in self.not_in_tiramisu: - value = getattr(self, variable) - if not isinstance(value, str): - value = value.copy() - setattr(rougailconfig, variable, value) - return rougailconfig + self.config.property.read_only() def __setitem__( self, key, value, ) -> None: + if self.root is None: + self.generate_config() if key in self.not_in_tiramisu: setattr(self, key, value) else: @@ -130,6 +144,8 @@ class _RougailConfig: self, key, ) -> None: + if self.root is None: + self.generate_config() if key in self.not_in_tiramisu: return getattr(self, key) if key == "export_with_import": @@ -199,11 +215,10 @@ class FakeRougailConvert(RougailConvert): self.load_unexist_redefine = False -def get_rougail_config( - *, +def _rougail_config( backward_compatibility: bool = True, add_extra_options: bool = True, -) -> _RougailConfig: +) -> "OptionDescription": rougail_options = f"""default_dictionary_format_version: description: Dictionary format version by default, if not specified in dictionary file alternative_name: v @@ -403,6 +418,23 @@ load_unexist_redefine: NAME=normalize_family(process), PROP=prop, ) + rougail_process += f""" +default_params: + description: {_("Default parameters for option type")} + +""" + for typ, params in get_convert_option_types(): + rougail_process += f""" + {typ}: +""" + for key, key_type, multi, value in params: + rougail_process += f""" + {key}: + type: {key_type} + multi: {multi} + mandatory: false + default: {value} +""" rougail_options += rougail_process # print(rougail_options) convert = FakeRougailConvert(add_extra_options) @@ -438,10 +470,17 @@ load_unexist_redefine: tiram_obj = convert.save() optiondescription = {} exec(tiram_obj, {}, optiondescription) # pylint: disable=W0122 + return optiondescription["option_0"], extra_vars + + +def get_rougail_config( + *, + backward_compatibility: bool = True, + add_extra_options: bool = True, +) -> _RougailConfig: return _RougailConfig( backward_compatibility, - optiondescription["option_0"], - extra_vars=extra_vars, + add_extra_options, ) diff --git a/src/rougail/convert.py b/src/rougail/convert.py index 3cc27b871..fab55ac47 100644 --- a/src/rougail/convert.py +++ b/src/rougail/convert.py @@ -10,7 +10,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the @@ -176,6 +176,16 @@ class ParserVariable: self.output = rougailconfig["step.output"] self.tiramisu_cache = rougailconfig["tiramisu_cache"] self.load_unexist_redefine = rougailconfig["load_unexist_redefine"] + # change default initkwargs in CONVERT_OPTION + if hasattr(rougailconfig, 'config'): + for sub_od in rougailconfig.config.option('default_params'): + for option in sub_od: + if option.owner.isdefault(): + continue + convert_option = CONVERT_OPTION[sub_od.name()] + if "initkwargs" not in convert_option: + convert_option["initkwargs"] = {} + convert_option["initkwargs"][option.name()] = option.value.get() def init(self): if self.is_init: diff --git a/src/rougail/error.py b/src/rougail/error.py index 9cb99aadb..c39e21b69 100644 --- a/src/rougail/error.py +++ b/src/rougail/error.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/i18n.py b/src/rougail/i18n.py index 38f2fb6f1..566e5626e 100644 --- a/src/rougail/i18n.py +++ b/src/rougail/i18n.py @@ -8,7 +8,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/object_model.py b/src/rougail/object_model.py index 995fba0bd..25f0c0d8c 100644 --- a/src/rougail/object_model.py +++ b/src/rougail/object_model.py @@ -1,7 +1,7 @@ """Rougail object model Silique (https://www.silique.fr) -Copyright (C) 2023-2024 +Copyright (C) 2023-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the @@ -27,6 +27,7 @@ from pydantic import ( ConfigDict, ) from tiramisu import undefined +import tiramisu from .utils import get_jinja_variable_to_param from .error import DictConsistencyError, VariableCalculationDependencyError @@ -105,6 +106,35 @@ CONVERT_OPTION = { } +def get_convert_option_types(): + for typ, datas in CONVERT_OPTION.items(): + obj = getattr(tiramisu, datas["opttype"]) + initkwargs = datas.get("initkwargs", {}) + if obj == tiramisu.SymLinkOption: + continue + if obj == tiramisu.ChoiceOption: + inst = obj('a', 'a', ('a',), **initkwargs) + else: + inst = obj('a', 'a', **initkwargs) + extra = getattr(inst, '_extra', {}) + if not extra: + continue + params = [] + for key, value in extra.items(): + if key.startswith('_'): + continue + multi = False + if isinstance(value, bool): + key_type = 'boolean' + elif isinstance(value, str): + key_type = 'string' + elif isinstance(value, list): + key_type = 'string' + multi = True + params.append((key, key_type, multi, value)) + yield typ, params + + class Param(BaseModel): key: str model_config = ConfigDict(extra="forbid") diff --git a/src/rougail/path.py b/src/rougail/path.py index cdfb24e01..b0dbf799d 100644 --- a/src/rougail/path.py +++ b/src/rougail/path.py @@ -1,5 +1,5 @@ """ -Copyright (C) 2024 +Copyright (C) 2024-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/structural_commandline/__init__.py b/src/rougail/structural_commandline/__init__.py index d4a05accb..1d78ef63a 100644 --- a/src/rougail/structural_commandline/__init__.py +++ b/src/rougail/structural_commandline/__init__.py @@ -1,6 +1,6 @@ """ Silique (https://www.silique.fr) -Copyright (C) 2024 +Copyright (C) 2024-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/structural_commandline/config.py b/src/rougail/structural_commandline/config.py index 3b9dd6cf8..f865fdc47 100644 --- a/src/rougail/structural_commandline/config.py +++ b/src/rougail/structural_commandline/config.py @@ -2,7 +2,7 @@ Config file for Rougail-structural_commandline Silique (https://www.silique.fr) -Copyright (C) 2024 +Copyright (C) 2024-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/structural_commandline/object_model.py b/src/rougail/structural_commandline/object_model.py index 0de5bac64..404051ee2 100644 --- a/src/rougail/structural_commandline/object_model.py +++ b/src/rougail/structural_commandline/object_model.py @@ -1,7 +1,7 @@ """Annotate to add specify attribute for tiramisu-cmdline Silique (https://www.silique.fr) -Copyright (C) 2024 +Copyright (C) 2024-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/structural_directory/__init__.py b/src/rougail/structural_directory/__init__.py index 5d0b37a80..8288f24bc 100644 --- a/src/rougail/structural_directory/__init__.py +++ b/src/rougail/structural_directory/__init__.py @@ -1,6 +1,6 @@ """ Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/structural_directory/config.py b/src/rougail/structural_directory/config.py index 3f56be244..8a983f767 100644 --- a/src/rougail/structural_directory/config.py +++ b/src/rougail/structural_directory/config.py @@ -1,6 +1,6 @@ """ Silique (https://www.silique.fr) -Copyright (C) 2024 +Copyright (C) 2024-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/tiramisu.py b/src/rougail/tiramisu.py index 710740ec1..0ce12895f 100644 --- a/src/rougail/tiramisu.py +++ b/src/rougail/tiramisu.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/tiramisureflector.py b/src/rougail/tiramisureflector.py index 1bf5daf01..1f59134b2 100644 --- a/src/rougail/tiramisureflector.py +++ b/src/rougail/tiramisureflector.py @@ -10,7 +10,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the diff --git a/src/rougail/user_datas.py b/src/rougail/user_datas.py index b80ccdecd..36497eb96 100644 --- a/src/rougail/user_datas.py +++ b/src/rougail/user_datas.py @@ -1,6 +1,6 @@ """ Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 distribued with GPL-2 or later license @@ -151,7 +151,7 @@ class UserDatas: if path not in self.values: continue options = self.values[path].get("options", {}) - if options.get('allow_secrets_variables', False) is True and option.type() == 'password': + if options.get('allow_secrets_variables', True) is False and option.type() == 'password': self.errors.append(_('the variable "{0}" contains secrets and should not be defined in {1}').format(path, self.values[path]["source"])) continue value = self.values[path]["values"] diff --git a/src/rougail/utils.py b/src/rougail/utils.py index 5eb64ef29..be6f73b30 100644 --- a/src/rougail/utils.py +++ b/src/rougail/utils.py @@ -9,7 +9,7 @@ Cadoles (http://www.cadoles.com) Copyright (C) 2019-2021 Silique (https://www.silique.fr) -Copyright (C) 2022-2024 +Copyright (C) 2022-2025 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the @@ -159,7 +159,5 @@ def get_jinja_variable_to_param( break if root_path: yield {}, None, root_path - else: - yield {}, None, vpath for variable_path, data in founded_variables.items(): yield data[1], data[0], variable_path