fix: black

This commit is contained in:
egarette@silique.fr 2025-05-11 19:13:12 +02:00
parent 561d117d4d
commit 263dae2b2c
4 changed files with 72 additions and 29 deletions

View file

@ -272,7 +272,7 @@ class Annotator(Walk):
return True return True
def _calculation_to_information_variable( def _calculation_to_information_variable(
self, variable_path: str, values, prop: str, version: str, path: str self, variable_path: str, values, prop: str, version: str, path: str
) -> str: ) -> str:
# is optional # is optional
variable = self.objectspace.paths.get_with_dynamic( variable = self.objectspace.paths.get_with_dynamic(

View file

@ -171,7 +171,7 @@ class RougailOutputDoc(Examples):
return True return True
calculation = child.information.get(f"{hidden_property}_calculation", None) calculation = child.information.get(f"{hidden_property}_calculation", None)
if calculation and calculation.get('type') == 'variable': if calculation and calculation.get("type") == "variable":
variable_path, value, condition = calculation["value"] variable_path, value, condition = calculation["value"]
variable = self.conf.forcepermissive.option(variable_path) variable = self.conf.forcepermissive.option(variable_path)
try: try:
@ -180,8 +180,16 @@ class RougailOutputDoc(Examples):
pass pass
else: else:
uncalculated = variable.value.get(uncalculated=True) uncalculated = variable.value.get(uncalculated=True)
if not isinstance(uncalculated, Calculation) and self._is_inaccessible_user_data(variable) and (condition == 'when' and value == variable_value or if (
condition == 'when_not' and value != variable_value): not isinstance(uncalculated, Calculation)
and self._is_inaccessible_user_data(variable)
and (
condition == "when"
and value == variable_value
or condition == "when_not"
and value != variable_value
)
):
return True return True
if not child.isoptiondescription(): if not child.isoptiondescription():
for hidden_property in self.disabled_modes: for hidden_property in self.disabled_modes:
@ -245,9 +253,9 @@ class RougailOutputDoc(Examples):
return None return None
def _parse_variable_follower_with_index( def _parse_variable_follower_with_index(
self, variable, leader: dict, path: str, informations: dict self, variable, leader: dict, path: str, informations: dict
) -> None: ) -> None:
if not self.example or (variable.index() + 1) > len(leader['example'][-1]): if not self.example or (variable.index() + 1) > len(leader["example"][-1]):
return return
informations[path]["example"][-1][variable.index()] = self._get_example( informations[path]["example"][-1][variable.index()] = self._get_example(
variable, informations[path], None variable, informations[path], None
@ -262,10 +270,14 @@ class RougailOutputDoc(Examples):
dynamic_variable["example"].append( dynamic_variable["example"].append(
self._get_example(variable, dynamic_variable, leader) self._get_example(variable, dynamic_variable, leader)
) )
description = self.formater.to_phrase(variable.description(uncalculated=True)) description = self.formater.to_phrase(
variable.description(uncalculated=True)
)
if "{{ identifier }}" in description: if "{{ identifier }}" in description:
description = self._convert_description(description, variable) description = self._convert_description(description, variable)
dynamic_variable["descriptions"].append(self.formater.to_phrase(description)) dynamic_variable["descriptions"].append(
self.formater.to_phrase(description)
)
if variable.isleader(): if variable.isleader():
return dynamic_variable return dynamic_variable
return None return None
@ -335,7 +347,9 @@ class RougailOutputDoc(Examples):
) )
self._populate(variable, informations) self._populate(variable, informations)
if "description" in informations: if "description" in informations:
informations["descriptions"] = [self.formater.to_phrase(informations.pop("description"))] informations["descriptions"] = [
self.formater.to_phrase(informations.pop("description"))
]
if variable.ismulti(): if variable.ismulti():
multi = not variable.isfollower() or variable.issubmulti() multi = not variable.isfollower() or variable.issubmulti()
else: else:
@ -363,7 +377,8 @@ class RougailOutputDoc(Examples):
informations["names"] = [obj.name()] informations["names"] = [obj.name()]
description = obj.description(uncalculated=True) description = obj.description(uncalculated=True)
if obj.name(uncalculated=True) == description and ( if obj.name(uncalculated=True) == description and (
not obj.isoptiondescription() or (self.support_namespace and obj.group_type() is not groups.namespace) not obj.isoptiondescription()
or (self.support_namespace and obj.group_type() is not groups.namespace)
): ):
warning = _('No attribute "description" for "{0}" in {1}').format( warning = _('No attribute "description" for "{0}" in {1}').format(
obj.path(uncalculated=True), obj.path(uncalculated=True),
@ -392,7 +407,10 @@ class RougailOutputDoc(Examples):
informations["example"] = [example] informations["example"] = [example]
informations["mandatory_without_value"] = "mandatory" in variable.property.get( informations["mandatory_without_value"] = "mandatory" in variable.property.get(
uncalculated=True uncalculated=True
) and (not variable.information.get("default_value_makes_sense", True) or variable.value.get(uncalculated=True) in [None, []]) ) and (
not variable.information.get("default_value_makes_sense", True)
or variable.value.get(uncalculated=True) in [None, []]
)
def _get_example(self, variable, informations: dict, leader): def _get_example(self, variable, informations: dict, leader):
example = informations.get("examples") example = informations.get("examples")
@ -480,7 +498,11 @@ class RougailOutputDoc(Examples):
if not isinstance(val, Calculation): if not isinstance(val, Calculation):
default = informations.get("default") default = informations.get("default")
if default is not None and val == default: if default is not None and val == default:
choices[idx] = str(val) + " " + self.formater.bold("" + _("(default)")) choices[idx] = (
str(val)
+ " "
+ self.formater.bold("" + _("(default)"))
)
informations["display_default"] = False informations["display_default"] = False
continue continue
choices[idx] = self._to_string(variable, "choice", f"_{idx}") choices[idx] = self._to_string(variable, "choice", f"_{idx}")
@ -600,7 +622,9 @@ class RougailOutputDoc(Examples):
variable = None variable = None
else: else:
uncalculated = variable.value.get(uncalculated=True) uncalculated = variable.value.get(uncalculated=True)
if not isinstance(uncalculated, Calculation) and self._is_inaccessible_user_data(variable): if not isinstance(
uncalculated, Calculation
) and self._is_inaccessible_user_data(variable):
return None return None
if variable and self._is_inaccessible_user_data(variable): if variable and self._is_inaccessible_user_data(variable):
msg = _("depends on an undocumented variable") msg = _("depends on an undocumented variable")
@ -626,10 +650,16 @@ class RougailOutputDoc(Examples):
hidden_msg = _("the value of an undocumented variable") hidden_msg = _("the value of an undocumented variable")
# if "{{ identifier }}" in calculation["value"] and calculation["value"] in self.dynamic_paths: # if "{{ identifier }}" in calculation["value"] and calculation["value"] in self.dynamic_paths:
if "{{ identifier }}" in calculation["ori_path"]: if "{{ identifier }}" in calculation["ori_path"]:
if calculation["value"] == calculation['ori_path']: if calculation["value"] == calculation["ori_path"]:
regexp = None regexp = None
else: else:
regexp = compile("^" + calculation["ori_path"].replace("{{ identifier }}", "(.*)") + "$") regexp = compile(
"^"
+ calculation["ori_path"].replace(
"{{ identifier }}", "(.*)"
)
+ "$"
)
informations = [self.dynamic_paths[calculation["value"]]] informations = [self.dynamic_paths[calculation["value"]]]
values = [] values = []
all_is_undocumented = None all_is_undocumented = None
@ -643,10 +673,12 @@ class RougailOutputDoc(Examples):
msg = hidden_msg msg = hidden_msg
else: else:
if regexp: if regexp:
display_path = calculation['ori_path'] display_path = calculation["ori_path"]
for identifier in regexp.findall(path): for identifier in regexp.findall(path):
display_path = display_path.replace( display_path = display_path.replace(
"{{ identifier }}", self.formater.italic(identifier), 1 "{{ identifier }}",
self.formater.italic(identifier),
1,
) )
else: else:
display_path = get_display_path(information, idx) display_path = get_display_path(information, idx)
@ -668,16 +700,22 @@ class RougailOutputDoc(Examples):
uncalculated = variable.value.get(uncalculated=True) uncalculated = variable.value.get(uncalculated=True)
except PropertiesOptionError: except PropertiesOptionError:
true_msg = None true_msg = None
# true_msg = _("depends on an undocumented variable") # true_msg = _("depends on an undocumented variable")
else: else:
if uncalculated and not isinstance(uncalculated, Calculation): if uncalculated and not isinstance(
uncalculated, Calculation
):
if isinstance(uncalculated, list): if isinstance(uncalculated, list):
uncalculated = self.formater.list(uncalculated) uncalculated = self.formater.list(uncalculated)
true_msg = _('(from an undocumented variable){0}').format(uncalculated) true_msg = _(
"(from an undocumented variable){0}"
).format(uncalculated)
else: else:
if not isinstance(uncalculated, str): if not isinstance(uncalculated, str):
uncalculated = dump(uncalculated) uncalculated = dump(uncalculated)
true_msg = _('{0} (from an undocumented variable)').format(uncalculated) true_msg = _(
"{0} (from an undocumented variable)"
).format(uncalculated)
else: else:
true_msg = _("depends on an undocumented variable") true_msg = _("depends on an undocumented variable")
if true_msg: if true_msg:

View file

@ -15,6 +15,7 @@ details.
You should have received a copy of the GNU Lesser General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from typing import List from typing import List
from ..i18n import _ from ..i18n import _
@ -27,12 +28,13 @@ class Formater(CommonFormater):
name = "console" name = "console"
level = 10 level = 10
enter_table = "\n" enter_table = "\n"
titles_color = {"title1": "bright_cyan underline bold", titles_color = {
"title2": "bright_green underline bold", "title1": "bright_cyan underline bold",
"title3": "green1 underline bold", "title2": "bright_green underline bold",
"title4": "green3 underline bold", "title3": "green1 underline bold",
"title5": "dark_green underline bold", "title4": "green3 underline bold",
} "title5": "dark_green underline bold",
}
def __init__(self) -> None: def __init__(self) -> None:
self.max_line = 0 self.max_line = 0
@ -43,6 +45,7 @@ class Formater(CommonFormater):
from rich.table import Table from rich.table import Table
from rich.theme import Theme from rich.theme import Theme
from rich.console import Console from rich.console import Console
self.rich_table = Table self.rich_table = Table
custom_theme = Theme(self.titles_color) custom_theme = Theme(self.titles_color)
@ -125,7 +128,7 @@ class Formater(CommonFormater):
) -> str: ) -> str:
"""Add a link""" """Add a link"""
return self.prop(comment, False) return self.prop(comment, False)
#return f"{comment} ({link})" # return f"{comment} ({link})"
def columns( def columns(
self, self,

View file

@ -253,7 +253,9 @@ class CommonFormater:
for help_ in helps: for help_ in helps:
msg.append(help_.strip() + ENTER) msg.append(help_.strip() + ENTER)
if "identifiers" in informations: if "identifiers" in informations:
msg.append(self.section(_("Identifiers"), informations["identifiers"]) + ENTER) msg.append(
self.section(_("Identifiers"), informations["identifiers"]) + ENTER
)
return msg return msg
def family_description(self, informations: dict) -> str(): def family_description(self, informations: dict) -> str():