rougail-output-doc/src/rougail/output_doc/config.py

209 lines
6 KiB
Python
Raw Normal View History

2024-07-10 21:27:48 +02:00
"""
Config file for Rougail-doc
Silique (https://www.silique.fr)
2025-02-10 09:52:12 +01:00
Copyright (C) 2024-2025
2024-07-10 21:27:48 +02:00
2024-11-01 11:17:14 +01:00
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/>.
2024-07-10 21:27:48 +02:00
"""
2024-11-01 11:17:14 +01:00
2024-07-10 21:27:48 +02:00
from pathlib import Path
2025-10-14 12:58:39 +02:00
from rougail.utils import load_modules
from .i18n import _
2024-07-10 21:27:48 +02:00
OUTPUTS = None
def get_outputs() -> None:
2024-11-15 08:13:45 +01:00
"""Load all outputs"""
module_name = "rougail.output_doc.output"
2024-07-10 21:27:48 +02:00
outputs = {}
2024-11-01 11:17:14 +01:00
for path in (Path(__file__).parent / "output").iterdir():
2024-07-10 21:27:48 +02:00
name = path.name
if not name.endswith(".py") or name.endswith("__.py"):
continue
2024-11-15 08:13:45 +01:00
module = load_modules(module_name + "." + name[:-3], str(path))
2025-10-27 21:59:39 +01:00
if "Formatter" not in dir(module):
2024-07-10 21:27:48 +02:00
continue
2025-10-27 21:59:39 +01:00
level = module.Formatter.level
2024-07-10 21:27:48 +02:00
if level in outputs:
2024-11-15 08:13:45 +01:00
raise ImportError(
_('duplicated level rougail-doc for output "{0}": {1} and {2}').format(
2025-10-27 21:59:39 +01:00
level, module.Formatter.name, outputs[level].name
2024-11-15 08:13:45 +01:00
)
2024-11-01 11:17:14 +01:00
)
2025-10-27 21:59:39 +01:00
outputs[module.Formatter.level] = module.Formatter
2024-07-10 21:27:48 +02:00
return {outputs[level].name: outputs[level] for level in sorted(outputs)}
class OutPuts: # pylint: disable=R0903
"""Transformations applied on a object instance"""
def __init__(
self,
) -> None:
global OUTPUTS
if OUTPUTS is None:
OUTPUTS = get_outputs()
def get(self) -> dict:
2024-11-15 08:13:45 +01:00
"""Get all outputs"""
2024-07-10 21:27:48 +02:00
return OUTPUTS
2024-11-01 11:17:14 +01:00
def get_rougail_config(
*,
2024-11-15 08:13:45 +01:00
backward_compatibility=True, # pylint: disable=unused-argument
2024-11-01 11:17:14 +01:00
) -> dict:
2024-11-15 08:13:45 +01:00
"""Get documentation for output_doc modules"""
2024-07-10 21:27:48 +02:00
outputs = list(OutPuts().get())
output_format_default = outputs[0]
2025-02-17 20:53:58 +01:00
rougail_options = f"""
2024-07-10 21:27:48 +02:00
doc:
2025-02-17 20:53:58 +01:00
description: {_('Configuration rougail-doc')}
2024-07-10 21:27:48 +02:00
disabled:
jinja: |
{{% if step.output is propertyerror or step.output != 'doc' %}}
2024-07-10 21:27:48 +02:00
disabled
2025-02-17 20:53:58 +01:00
{{% endif %}}
2024-07-10 21:27:48 +02:00
title_level:
2025-02-17 20:53:58 +01:00
description: {_('Starting title level')}
2024-07-10 21:27:48 +02:00
alternative_name: dt
default: 1
2025-10-14 12:58:39 +02:00
contents:
description: {_('Generated content')}
choices:
- variables
- example
- changelog
default:
- variables
previous_json_file:
description: {_('Previous description file in JSON format')}
disabled:
jinja: |-
{{{{ "changelog" not in _.contents }}}}
return_type: boolean
description: changelog is not selected
2025-10-14 12:58:39 +02:00
without_family:
2025-02-17 20:53:58 +01:00
description: {_('Do not add families in documentation')}
default: false
2025-10-14 12:58:39 +02:00
disabled:
jinja: |-
{{{{ "variables" not in _.contents and "changelog" not in _.contents and _.output_format != "json" }}}}
2025-10-14 12:58:39 +02:00
return_type: boolean
description: variables is not selected
2025-10-27 21:59:39 +01:00
root:
description: {_('Document the variables from this family')}
mandatory: false
2025-10-29 10:46:57 +01:00
other_root_filenames:
description: {_("Families or variables for this family are in an other file name")}
type: leadership
disabled:
jinja: |-
{{% if not _.root %}}
Documents are not splitted
{{% endif %}}
{{% if _.output_format != 'gitlab' %}}
anchor is available only for gitlab output_format
{{% endif %}}
description: {_('documentation must be splitted and in gitlab format')}
root_path:
description: {_("Root family name")}
mandatory: false
filename:
description: {_("Name of the file")}
type: unix_filename
params:
allow_relative: true
disabled_modes:
2025-02-17 20:53:58 +01:00
description: {_('Disable documentation for variables with those modes')}
multi: true
mandatory: false
disabled:
jinja: |
2025-02-17 20:53:58 +01:00
{{% if not modes_level %}}
there is no mode
2025-02-17 20:53:58 +01:00
{{% endif %}}
description: {_('disabled when there is no mode available')}
validators:
- jinja: |
2025-02-17 20:53:58 +01:00
{{% if _.disabled_modes not in modes_level %}}
this mode is not available
2025-02-17 20:53:58 +01:00
{{% endif %}}
description: {_('verify if disable modes already exists')}
2025-10-14 12:58:39 +02:00
change_default_value: true # {_('Modify values to document leaderships and dynamics families')}
comment_examples:
description: {_('Add description of variables and families when generate examples')}
default: false
disabled:
jinja: |-
{{{{ "example" not in _.contents }}}}
return_type: boolean
description: {_('disabled when example in not in contents')}
2025-10-29 10:46:57 +01:00
comment_examples_column:
description: {_('Comment in examples starts at column')}
default: 30
disabled:
variable: _.comment_examples
2025-10-29 10:46:57 +01:00
propertyerror: false
when: false
2024-07-10 21:27:48 +02:00
output_format:
2025-02-17 20:53:58 +01:00
description: {_('Generate document in format')}
2024-07-10 21:27:48 +02:00
alternative_name: do
default: output_format_default
2025-10-14 12:58:39 +02:00
validators:
- jinja: |-
{{% if _.output_format == 'json' %}}
2025-10-27 21:59:39 +01:00
{{% if "changelog" in _.contents or "example" in _.contents %}}
cannot add to contents "{{{{ _.contents }}}}" with output_format "json"
2025-10-14 12:58:39 +02:00
{{% endif %}}
{{% endif %}}
2025-10-27 21:59:39 +01:00
description: {_('json output_format is not compatible with "changelog" and "example" contents')}
2024-07-10 21:27:48 +02:00
choices:
2024-11-01 11:17:14 +01:00
""".replace(
"output_format_default", output_format_default
)
2024-07-10 21:27:48 +02:00
for output in outputs:
rougail_options += f" - {output}\n"
rougail_options += f"""
force_true_color_terminal:
description: {_('Force true color terminal')}
default: false
"""
2024-11-01 11:17:14 +01:00
return {
"name": "doc",
"process": "output",
"options": rougail_options,
"allow_user_data": False,
"level": 50,
}
2024-07-10 21:27:48 +02:00
2024-11-01 11:17:14 +01:00
__all__ = ("OutPuts", "get_rougail_config")