fix: black

This commit is contained in:
egarette@silique.fr 2025-11-08 22:18:16 +01:00
parent 1fa70b1365
commit c064f6519d

View file

@ -43,14 +43,14 @@ class RougailOutputConsole:
def __init__( def __init__(
self, self,
config: "Config", config: "Config",
metaconfig = None, metaconfig=None,
*, *,
rougailconfig: "RougailConfig" = None, rougailconfig: "RougailConfig" = None,
user_data_errors: Optional[list] = None, user_data_errors: Optional[list] = None,
user_data_warnings: Optional[list] = None, user_data_warnings: Optional[list] = None,
config_owner_is_path: bool = False, config_owner_is_path: bool = False,
layer_datas = None, layer_datas=None,
**kwargs **kwargs,
) -> None: ) -> None:
if rougailconfig is None: if rougailconfig is None:
from rougail import RougailConfig from rougail import RougailConfig
@ -102,14 +102,16 @@ class RougailOutputConsole:
else: else:
parent = self.config parent = self.config
current_options = options current_options = options
for child_path in option.path().split('.'): for child_path in option.path().split("."):
child = parent.option(child_path) child = parent.option(child_path)
if self.key_is_description: if self.key_is_description:
description = child.description(uncalculated=True) description = child.description(uncalculated=True)
else: else:
description = child.path(uncalculated=True) description = child.path(uncalculated=True)
if child.isdynamic() and "{{ identifier }}" in description: if child.isdynamic() and "{{ identifier }}" in description:
description = description.replace('{{ identifier }}', child.identifiers()[-1]) description = description.replace(
"{{ identifier }}", child.identifiers()[-1]
)
if child.isoptiondescription(): if child.isoptiondescription():
current_options = current_options.setdefault(description, {}) current_options = current_options.setdefault(description, {})
@ -117,15 +119,21 @@ class RougailOutputConsole:
else: else:
current_options.setdefault(None, []).append(description) current_options.setdefault(None, []).append(description)
if options: if options:
self.errors.append({_("The following variables are mandatory but have no value:"): options}) self.errors.append(
{_("The following variables are mandatory but have no value:"): options}
)
elif options_with_error: elif options_with_error:
if self.key_is_description: if self.key_is_description:
variables = [option.description() for option in options_with_error] variables = [option.description() for option in options_with_error]
else: else:
variables = [option.path() for option in options_with_error] variables = [option.path() for option in options_with_error]
self.errors.append({_( self.errors.append(
"The following variables are inaccessible but are empty and mandatory:" {
): variables}) _(
"The following variables are inaccessible but are empty and mandatory:"
): variables
}
)
def exporter(self) -> bool: def exporter(self) -> bool:
if self.is_mandatory: if self.is_mandatory:
@ -359,10 +367,13 @@ class OutputFamily:
key_name = option.name() key_name = option.name()
return OutputFamily( return OutputFamily(
self.colorize( self.colorize(
[{"value": key_name, [
"color": color, {
"loaded_from": None, "value": key_name,
}] "color": color,
"loaded_from": None,
}
]
), ),
self.tree, self.tree,
self.root, self.root,
@ -402,13 +413,18 @@ class OutputFamily:
loaded_from = option.information.get("loaded_from", None) loaded_from = option.information.get("loaded_from", None)
if value is undefined: if value is undefined:
value = option.value.get() value = option.value.get()
values.append({"value": value, values.append(
"color": color, {
"loaded_from": loaded_from, "value": value,
}) "color": color,
"loaded_from": loaded_from,
}
)
suboption = option suboption = option
subconfig = self.root.config subconfig = self.root.config
if "force_store_value" not in option.property.get() and option.information.get("default_value_makes_sense", True): if "force_store_value" not in option.property.get() and option.information.get(
"default_value_makes_sense", True
):
while True: while True:
default_value = suboption.value.default() default_value = suboption.value.default()
if leader_index is not None: if leader_index is not None:
@ -417,10 +433,16 @@ class OutputFamily:
else: else:
default_value = None default_value = None
is_root_metaconfig = False is_root_metaconfig = False
if subconfig is None or not subconfig.path() or "." not in subconfig.path(): if (
subconfig is None
or not subconfig.path()
or "." not in subconfig.path()
):
is_root_metaconfig = True is_root_metaconfig = True
subconfig = self.get_subconfig_with_default_value(suboption) subconfig = self.get_subconfig_with_default_value(suboption)
if ((values and default_value is None) or default_value == []) and is_root_metaconfig: if (
(values and default_value is None) or default_value == []
) and is_root_metaconfig:
break break
if not values: if not values:
self.root.value_unmodified_enable = True self.root.value_unmodified_enable = True
@ -442,10 +464,13 @@ class OutputFamily:
else: else:
key = "loaded_from" key = "loaded_from"
loaded_from = parent_option.information.get(key, None) loaded_from = parent_option.information.get(key, None)
values.append({"value": default_value, values.append(
"color": color, {
"loaded_from": loaded_from, "value": default_value,
}) "color": color,
"loaded_from": loaded_from,
}
)
if is_root_metaconfig: if is_root_metaconfig:
break break
elif not values: elif not values:
@ -462,19 +487,25 @@ class OutputFamily:
else: else:
self.root.value_default_enable = True self.root.value_default_enable = True
color = self.root.value_default_color color = self.root.value_default_color
values.append({"value": None, values.append(
"color": color, {
"loaded_from": loaded_from, "value": None,
}) "color": color,
"loaded_from": loaded_from,
}
)
if self.key_is_description: if self.key_is_description:
key_name = option.description() key_name = option.description()
else: else:
key_name = option.name() key_name = option.name()
key = self.colorize( key = self.colorize(
[{"value": key_name, [
"color": variable_color, {
"loaded_from": None, "value": key_name,
}] "color": variable_color,
"loaded_from": None,
}
]
) )
value = self.colorize( value = self.colorize(
values, values,
@ -502,14 +533,14 @@ class OutputFamily:
break break
else: else:
subconfig = self.root.metaconfig subconfig = self.root.metaconfig
for child in default_owner.split('.')[1:]: for child in default_owner.split(".")[1:]:
subconfig = subconfig.config(child) subconfig = subconfig.config(child)
return subconfig return subconfig
def colorize( def colorize(
self, self,
values, values,
option = None, option=None,
) -> str: ) -> str:
multi = False multi = False
ret = [] ret = []
@ -561,7 +592,11 @@ class OutputFamily:
value: Any, value: Any,
) -> str: ) -> str:
"""Dump variable, means transform bool, ... to yaml string""" """Dump variable, means transform bool, ... to yaml string"""
if value is not None and not self.root.show_secrets and option.type() == "password": if (
value is not None
and not self.root.show_secrets
and option.type() == "password"
):
return "*" * 10 return "*" * 10
if isinstance(value, str): if isinstance(value, str):
return value return value