WIP: Expand the developer documentation #27
2 changed files with 184 additions and 0 deletions
115
src/rougail/structural_string/__init__.py
Normal file
115
src/rougail/structural_string/__init__.py
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
"""
|
||||||
|
Silique (https://www.silique.fr)
|
||||||
|
Copyright (C) 2025-2026
|
||||||
|
|
||||||
|
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
|
||||||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
from itertools import chain
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
from ..tiramisu import normalize_family
|
||||||
|
from ..convert.path import Paths
|
||||||
|
#from ..error import DictConsistencyError
|
||||||
|
#from ..i18n import _
|
||||||
|
|
||||||
|
|
||||||
|
class Walker:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
convert,
|
||||||
|
) -> None:
|
||||||
|
"""Parse directories content"""
|
||||||
|
self.convert = convert
|
||||||
|
self.yaml = YAML()
|
||||||
|
rougailconfig = self.convert.rougailconfig
|
||||||
|
if rougailconfig["main_namespace"]:
|
||||||
|
self.convert.has_namespace = True
|
||||||
|
self.convert.paths = Paths(
|
||||||
|
rougailconfig["main_namespace"],
|
||||||
|
rougailconfig["isolated_namespace"],
|
||||||
|
)
|
||||||
|
self.load_with_extra(
|
||||||
|
rougailconfig["extra_namespaces"],
|
||||||
|
rougailconfig["main_namespace"],
|
||||||
|
rougailconfig["main_structural_strings"],
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.convert.namespace = None
|
||||||
|
namespace_path = ""
|
||||||
|
if namespace_path in self.convert.parents:
|
||||||
|
raise Exception("pfff")
|
||||||
|
for string in rougailconfig["main_structural_strings"]:
|
||||||
|
self.parse_variable(
|
||||||
|
string,
|
||||||
|
namespace_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
def load_with_extra(
|
||||||
|
self,
|
||||||
|
extra_structures: dict,
|
||||||
|
main_namespace: str,
|
||||||
|
main_strings: Optional[List[str]] = None,
|
||||||
|
) -> None:
|
||||||
|
directory_dict = chain(
|
||||||
|
(
|
||||||
|
(
|
||||||
|
main_namespace,
|
||||||
|
main_strings,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
extra_structures.items(),
|
||||||
|
)
|
||||||
|
for namespace, extra_objects in directory_dict:
|
||||||
|
namespace_path = normalize_family(namespace)
|
||||||
|
if namespace_path in self.convert.parents:
|
||||||
|
raise Exception("pfff")
|
||||||
|
self.convert.namespace = namespace_path
|
||||||
|
for idx, string in enumerate(extra_objects):
|
||||||
|
if not idx:
|
||||||
|
# create only for the first file
|
||||||
|
self.convert.create_namespace(namespace, namespace_path)
|
||||||
|
self.parse_variable(
|
||||||
|
string,
|
||||||
|
namespace_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
def parse_variable(
|
||||||
|
self,
|
||||||
|
string: str,
|
||||||
|
path: str,
|
||||||
|
) -> None:
|
||||||
|
objects = self.yaml.load(string)
|
||||||
|
if objects is None:
|
||||||
|
return
|
||||||
|
if path:
|
||||||
|
name = f'yaml file for {path}'
|
||||||
|
else:
|
||||||
|
name = 'yaml file'
|
||||||
|
version = self.convert.validate_file_version(
|
||||||
|
objects,
|
||||||
|
name,
|
||||||
|
)
|
||||||
|
self.convert.parse_root_file(
|
||||||
|
[name],
|
||||||
|
path,
|
||||||
|
version,
|
||||||
|
objects,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("Walker",)
|
||||||
|
|
||||||
69
src/rougail/structural_string/config.py
Normal file
69
src/rougail/structural_string/config.py
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
"""
|
||||||
|
Silique (https://www.silique.fr)
|
||||||
|
Copyright (C) 2025-2026
|
||||||
|
|
||||||
|
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
|
||||||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from ..utils import _
|
||||||
|
|
||||||
|
|
||||||
|
def get_rougail_config(
|
||||||
|
*,
|
||||||
|
backward_compatibility=True,
|
||||||
|
) -> dict:
|
||||||
|
if backward_compatibility:
|
||||||
|
main_namespace_default = "rougail"
|
||||||
|
else:
|
||||||
|
main_namespace_default = "null"
|
||||||
|
options = f"""
|
||||||
|
main_structural_strings:
|
||||||
|
description: {_("Structural files contents")}
|
||||||
|
help: {_("This variable is a list of string with YAML file format")}
|
||||||
|
multi: true
|
||||||
|
disabled:
|
||||||
|
jinja: >-
|
||||||
|
{{% if 'string' not in _.step.structural %}}
|
||||||
|
true
|
||||||
|
{{% elif cli is defined and cli.versions is defined and cli.versions %}}
|
||||||
|
true
|
||||||
|
{{% else %}}
|
||||||
|
false
|
||||||
|
{{% endif %}}
|
||||||
|
return_type: boolean
|
||||||
|
description: {_('string is not in "_.step.structural"')}
|
||||||
|
|
||||||
|
extra_namespaces:
|
||||||
|
|
||||||
|
strings:
|
||||||
|
description: {_("Extra structural contents")}
|
||||||
|
help: {_("This variable is a list of string with YAML file format")}
|
||||||
|
alternative_name: xc
|
||||||
|
multi: true
|
||||||
|
disabled:
|
||||||
|
jinja: >-
|
||||||
|
{{{{ 'string' not in __.step.structural }}}}
|
||||||
|
return_type: boolean
|
||||||
|
description: {_('string is not in "__.step.structural"')}
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
"name": "string",
|
||||||
|
"process": "structural",
|
||||||
|
"options": options,
|
||||||
|
"level": 15,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = "get_rougail_config"
|
||||||
|
|
||||||
Loading…
Reference in a new issue