diff --git a/src/rougail/output_doc/changelog.py b/src/rougail/output_doc/changelog.py
index 396557c61..679099b3d 100644
--- a/src/rougail/output_doc/changelog.py
+++ b/src/rougail/output_doc/changelog.py
@@ -28,7 +28,7 @@ class Changelog: # pylint: disable=no-member,too-few-public-methods
def gen_doc_changelog(self):
"""Return changelog"""
with Path(self.previous_json_file).open() as outfh:
- previous_doc = loads(outfh.read())
+ previous_doc = loads(outfh.read())
self.load()
self._added_variables = []
self._modified_variables = []
@@ -39,6 +39,7 @@ class Changelog: # pylint: disable=no-member,too-few-public-methods
def parser(self, previous_families, new_families):
def add(new):
self.formater.variable_to_string(new, self._added_variables)
+
def remove(previous):
self._removed_variables.append(element)
@@ -66,7 +67,7 @@ class Changelog: # pylint: disable=no-member,too-few-public-methods
else:
add(new)
self.parser(previous["children"], {})
- elif previous["type"] != 'variable':
+ elif previous["type"] != "variable":
self.parser(previous["children"], new["children"])
else:
modified_attributes = {}
@@ -75,14 +76,21 @@ class Changelog: # pylint: disable=no-member,too-few-public-methods
prop_new = new.get(prop, [])
if prop_previous != prop_new:
name = None
- if isinstance(prop_previous, dict) and "values" in prop_previous:
+ if (
+ isinstance(prop_previous, dict)
+ and "values" in prop_previous
+ ):
name = prop_previous["name"]
- local_prop_previous = prop_previous = prop_previous["values"]
+ local_prop_previous = prop_previous = prop_previous[
+ "values"
+ ]
if not isinstance(prop_previous, list):
if prop == "default":
local_prop_previous = [prop_previous]
else:
- local_prop_previous = prop_previous = [prop_previous]
+ local_prop_previous = prop_previous = [
+ prop_previous
+ ]
else:
local_prop_previous = prop_previous
if isinstance(prop_new, dict) and "values" in prop_new:
@@ -95,36 +103,63 @@ class Changelog: # pylint: disable=no-member,too-few-public-methods
else:
prop_new = [prop_new]
if isinstance(prop_previous, list):
- prop_previous = [p for p in prop_previous if p not in prop_new]
+ prop_previous = [
+ p for p in prop_previous if p not in prop_new
+ ]
elif prop_previous in prop_new:
prop_new.remove(prop_previous)
prop_previous = []
prop_new = [p for p in prop_new if p not in local_prop_previous]
- if prop_previous not in [None, []] or prop_new not in [None, []]:
+ if prop_previous not in [None, []] or prop_new not in [
+ None,
+ [],
+ ]:
modified_attributes[prop] = (name, prop_previous, prop_new)
if not modified_attributes:
continue
- self.formater.variable_to_string(new, self._modified_variables, modified_attributes)
-
+ self.formater.variable_to_string(
+ new, self._modified_variables, modified_attributes
+ )
def display(self) -> str:
- msg = ''
+ msg = ""
if self._added_variables:
if len(self._added_variables) == 1:
- title = _('New variable')
+ title = _("New variable")
else:
- title = _('New variables')
- msg += self.formater.run([self.formater.title(title, self.level), self.formater.table(self._added_variables)], self.level, dico_is_already_treated=True)
+ title = _("New variables")
+ msg += self.formater.run(
+ [
+ self.formater.title(title, self.level),
+ self.formater.table(self._added_variables),
+ ],
+ self.level,
+ dico_is_already_treated=True,
+ )
if self._modified_variables:
if len(self._modified_variables) == 1:
- title = _('Modified variable')
+ title = _("Modified variable")
else:
- title = _('Modified variables')
- msg += self.formater.run([self.formater.title(title, self.level), self.formater.table(self._modified_variables)], self.level, dico_is_already_treated=True)
+ title = _("Modified variables")
+ msg += self.formater.run(
+ [
+ self.formater.title(title, self.level),
+ self.formater.table(self._modified_variables),
+ ],
+ self.level,
+ dico_is_already_treated=True,
+ )
if self._removed_variables:
if len(self._removed_variables) == 1:
- title = _('Deleted variable')
+ title = _("Deleted variable")
else:
- title = _('Deleted variables')
- msg += self.formater.run([self.formater.title(title, self.level), self.formater.list(self._removed_variables)], self.level, dico_is_already_treated=True)
+ title = _("Deleted variables")
+ msg += self.formater.run(
+ [
+ self.formater.title(title, self.level),
+ self.formater.list(self._removed_variables),
+ ],
+ self.level,
+ dico_is_already_treated=True,
+ )
return msg
diff --git a/src/rougail/output_doc/doc.py b/src/rougail/output_doc/doc.py
index 077423ba7..bcbb2ca1f 100644
--- a/src/rougail/output_doc/doc.py
+++ b/src/rougail/output_doc/doc.py
@@ -35,9 +35,9 @@ from .changelog import Changelog
HIDDEN_PROPERTIES = [
- "hidden",
- "disabled",
- ]
+ "hidden",
+ "disabled",
+]
class RougailOutputDoc(Examples, Changelog):
@@ -91,7 +91,7 @@ class RougailOutputDoc(Examples, Changelog):
else:
self.with_family = True
if "changelog" in self.contents:
- self.previous_json_file = rougailconfig['doc.previous_json_file']
+ self.previous_json_file = rougailconfig["doc.previous_json_file"]
self.formater = outputs[output_format](self.with_family)
self.informations = None
try:
@@ -105,7 +105,7 @@ class RougailOutputDoc(Examples, Changelog):
def run(self) -> str:
"""Print documentation in stdout"""
self.load()
- return_string = ''
+ return_string = ""
if "variables" in self.contents:
return_string += self.formater.run(self.informations, self.level)
if "example" in self.contents:
@@ -144,14 +144,19 @@ class RougailOutputDoc(Examples, Changelog):
new_name = True
description = obj.description(uncalculated=True)
name = obj.name(uncalculated=True)
- self.dynamic_paths[path] = {"names": [],
- "identifiers": [],
- "path": path,
- }
+ self.dynamic_paths[path] = {
+ "names": [],
+ "identifiers": [],
+ "path": path,
+ }
if not obj.information.get("forced_description", False):
- self.dynamic_paths[path]["description"] = self._convert_description(description, obj, type_, its_a_path=False)
+ self.dynamic_paths[path]["description"] = self._convert_description(
+ description, obj, type_, its_a_path=False
+ )
elif obj.isoptiondescription():
- self.dynamic_paths[path]["description"] = self._convert_description(description, obj, type_, its_a_path=True)
+ self.dynamic_paths[path]["description"] = self._convert_description(
+ description, obj, type_, its_a_path=True
+ )
dynamic_obj = self.dynamic_paths[path]
dynamic_obj["names"].append(obj.name())
dynamic_obj["identifiers"].append(obj.identifiers())
@@ -212,19 +217,20 @@ class RougailOutputDoc(Examples, Changelog):
sub_informations = self._parse_families(family)
if not sub_informations:
return
-# if self.with_family:
+ # if self.with_family:
family_informations = self._populate_family(
- family,
- path,
- )
+ family,
+ path,
+ )
if family_informations is not False:
informations[name] = {
"type": self._get_family_type(family),
"informations": family_informations,
"children": sub_informations,
}
-# else:
-# informations.update(sub_informations)
+
+ # else:
+ # informations.update(sub_informations)
def parse_variable(
self,
@@ -266,7 +272,7 @@ class RougailOutputDoc(Examples, Changelog):
if not self._populate_variable(
variable,
sub_informations,
- ):
+ ):
return None
if self.example:
self._add_examples(variable, sub_informations, leader)
@@ -319,7 +325,7 @@ class RougailOutputDoc(Examples, Changelog):
informations = self.dynamic_paths[path]
else:
informations = {}
- if not self._populate(family, informations, 'family'):
+ if not self._populate(family, informations, "family"):
return False
if family.isleadership():
informations.setdefault("help", []).append(
@@ -352,7 +358,7 @@ class RougailOutputDoc(Examples, Changelog):
variable,
informations,
)
- if not self._populate(variable, informations, 'variable'):
+ if not self._populate(variable, informations, "variable"):
return False
if variable.ismulti():
multi = not variable.isfollower() or variable.issubmulti()
@@ -389,21 +395,34 @@ class RougailOutputDoc(Examples, Changelog):
return False
name = child.name(uncalculated=True)
if child.information.get("forced_description", False):
- if not child.isoptiondescription() or not self.support_namespace or child.group_type() is not groups.namespace:
- if child.isoptiondescription() or not child.isfollower() or not child.index():
+ if (
+ not child.isoptiondescription()
+ or not self.support_namespace
+ or child.group_type() is not groups.namespace
+ ):
+ if (
+ child.isoptiondescription()
+ or not child.isfollower()
+ or not child.index()
+ ):
warning = _('No attribute "description" for "{0}" in {1}').format(
child.path(uncalculated=True),
display_xmlfiles(child.information.get("ymlfiles")),
)
- warn(warning,
- RougailWarning,
- )
+ warn(
+ warning,
+ RougailWarning,
+ )
if child.isoptiondescription():
- description = self._convert_description(child.description(uncalculated=True), child, type_, its_a_path=True)
+ description = self._convert_description(
+ child.description(uncalculated=True), child, type_, its_a_path=True
+ )
else:
description = None
else:
- description = self._convert_description(child.description(uncalculated=True), child, type_, its_a_path=False)
+ description = self._convert_description(
+ child.description(uncalculated=True), child, type_, its_a_path=False
+ )
if not child.isdynamic():
informations["path"] = child.path(uncalculated=True)
informations["names"] = [child.name()]
@@ -421,10 +440,10 @@ class RougailOutputDoc(Examples, Changelog):
def _convert_description(self, description, obj, type_, its_a_path=False):
if not its_a_path:
description = to_phrase(description, type_)
-# if "{{ identifier }}" in description:
-# description = {"description": description,
-# "identifier": obj.identifiers()[-1],
-# }
+ # if "{{ identifier }}" in description:
+ # description = {"description": description,
+ # "identifier": obj.identifiers()[-1],
+ # }
return description
def _add_examples(self, variable, informations: dict, leader) -> None:
@@ -528,9 +547,7 @@ class RougailOutputDoc(Examples, Changelog):
break
if child.information.get("type") == "regexp":
validators.append(
- _('text based with regular expressions "{0}"').format(
- child.pattern()
- )
+ _('text based with regular expressions "{0}"').format(child.pattern())
)
if validators:
if len(validators) == 1:
@@ -675,9 +692,10 @@ class RougailOutputDoc(Examples, Changelog):
child.path(),
display_xmlfiles(child.information.get("ymlfiles")),
)
- warn(warning,
- RougailWarning,
- )
+ warn(
+ warning,
+ RougailWarning,
+ )
return values
def _calculation_variable_to_string(self, child, calculation, prop):
@@ -696,7 +714,12 @@ class RougailOutputDoc(Examples, Changelog):
except VariableCalculationDependencyError:
msg = _("depends on an undocumented variable")
else:
- if condition == "when" and value == variable_value or condition == "when_not" and value != variable_value:
+ if (
+ condition == "when"
+ and value == variable_value
+ or condition == "when_not"
+ and value != variable_value
+ ):
if prop in HIDDEN_PROPERTIES:
return
# always "{prop}" (but depends on an undocumented variable)
@@ -707,12 +730,16 @@ class RougailOutputDoc(Examples, Changelog):
if not calculation["optional"]:
msg = _('when the variable "{0}" hasn\'t the value "{1}"')
else:
- msg = _('when the variable "{0}" is defined and hasn\'t the value "{1}"')
+ msg = _(
+ 'when the variable "{0}" is defined and hasn\'t the value "{1}"'
+ )
else:
if not calculation["optional"]:
msg = _('when the variable "{0}" has the value "{1}"')
else:
- msg = _('when the variable "{0}" is defined and has the value "{1}"')
+ msg = _(
+ 'when the variable "{0}" is defined and has the value "{1}"'
+ )
if not isinstance(value, str):
value = dump(value)
values = msg.format(variable_path, value)
@@ -738,16 +765,14 @@ class RougailOutputDoc(Examples, Changelog):
else:
regexp = compile(
"^"
- + calculation["ori_path"].replace(
- "{{ identifier }}", "(.*)"
- )
+ + calculation["ori_path"].replace("{{ identifier }}", "(.*)")
+ "$"
)
informations = [self.dynamic_paths[calculation["value"]]]
values = []
all_is_undocumented = None
for information in informations:
-# if calculation["ori_path"] == information['path']:
+ # if calculation["ori_path"] == information['path']:
path = information["path"]
for identifiers in information["identifiers"]:
cpath = calc_path(path, identifiers=identifiers)
@@ -759,9 +784,13 @@ class RougailOutputDoc(Examples, Changelog):
msg = hidden_msg
else:
if "{{ identifier }}" in path:
- msg = {"message": true_msg,
- "path": {"path": path, "identifiers": identifiers.copy()},
- }
+ msg = {
+ "message": true_msg,
+ "path": {
+ "path": path,
+ "identifiers": identifiers.copy(),
+ },
+ }
else:
msg = true_msg.format(path)
all_is_undocumented = False
@@ -786,9 +815,12 @@ class RougailOutputDoc(Examples, Changelog):
uncalculated, Calculation
):
if isinstance(uncalculated, list):
- true_msg = {"submessage": _("(from an undocumented variable)"),
- "values": uncalculated,
- }
+ true_msg = {
+ "submessage": _(
+ "(from an undocumented variable)"
+ ),
+ "values": uncalculated,
+ }
else:
if not isinstance(uncalculated, str):
uncalculated = dump(uncalculated)
diff --git a/src/rougail/output_doc/example.py b/src/rougail/output_doc/example.py
index 134b0426e..73d3ad274 100644
--- a/src/rougail/output_doc/example.py
+++ b/src/rougail/output_doc/example.py
@@ -118,6 +118,7 @@ class Examples: # pylint: disable=no-member,too-few-public-methods
examples_mandatories[name] = ret_m
if ret_e:
examples[name] = ret_e
+
ori_path = family["informations"]["path"]
if "identifiers" in family["informations"]:
for idx, identifiers in enumerate(family["informations"]["identifiers"]):
diff --git a/src/rougail/output_doc/output/asciidoc.py b/src/rougail/output_doc/output/asciidoc.py
index 75ec4af9e..7fb3aa6ad 100644
--- a/src/rougail/output_doc/output/asciidoc.py
+++ b/src/rougail/output_doc/output/asciidoc.py
@@ -112,7 +112,7 @@ class Formater(CommonFormater):
"""Dump yaml part of documentation"""
return f"[,yaml]\n----\n---\n{dump(_dump)}\n----\n"
- def table(self, datas: list, with_header: bool=True) -> str:
+ def table(self, datas: list, with_header: bool = True) -> str:
"""Transform list to a table in string format
we change the first line because we want that col has the same width
"""
diff --git a/src/rougail/output_doc/output/console.py b/src/rougail/output_doc/output/console.py
index 7ed84481a..6c832da53 100644
--- a/src/rougail/output_doc/output/console.py
+++ b/src/rougail/output_doc/output/console.py
@@ -154,7 +154,7 @@ class Formater(CommonFormater):
for l in line.split(self.enter_table):
self.max_line = max(self.max_line, len(l) + 1)
- def table(self, datas: list, with_header: bool=True) -> str:
+ def table(self, datas: list, with_header: bool = True) -> str:
"""Transform list to a table in string format"""
table = self.rich_table(show_lines=True)
if with_header:
diff --git a/src/rougail/output_doc/output/github.py b/src/rougail/output_doc/output/github.py
index 1b4990430..17d79184d 100644
--- a/src/rougail/output_doc/output/github.py
+++ b/src/rougail/output_doc/output/github.py
@@ -98,9 +98,9 @@ class Formater(CommonFormater):
def table_header(self, lst):
"""Manage the header of a table"""
- return lst[0] + " " * (self.max_line_variable - len(lst[0])), lst[1] + " " * (
- self.max_line_description - len(lst[1])
- )
+ return lst[0] + " " * (self.max_line_variable - len(lst[0])), lst[
+ 1
+ ] + " " * (self.max_line_description - len(lst[1]))
def yaml(self, _dump):
"""Dump yaml part of documentation"""
diff --git a/src/rougail/output_doc/output/gitlab.py b/src/rougail/output_doc/output/gitlab.py
index 5523f547a..593f4d5bd 100644
--- a/src/rougail/output_doc/output/gitlab.py
+++ b/src/rougail/output_doc/output/gitlab.py
@@ -35,11 +35,11 @@ class Formater(GithubFormater):
)
def title(self, title: str, level: int) -> str:
-# self.max_line_variable = 0
- return '' + title + '
\n\n'
+ # self.max_line_variable = 0
+ return "" + title + "
\n\n"
def end_family(self, level):
- return '
"
diff --git a/src/rougail/output_doc/output/html.py b/src/rougail/output_doc/output/html.py
index db207c482..00fc2552d 100644
--- a/src/rougail/output_doc/output/html.py
+++ b/src/rougail/output_doc/output/html.py
@@ -45,10 +45,10 @@ class Formater(CommonFormater):
previous = ""
for line in lst:
if string:
-# if self.is_list(previous.split("\n", 1)[-1]):
-# string += "
"
-# else:
- string += "
"
+ # if self.is_list(previous.split("\n", 1)[-1]):
+ # string += "
"
+ # else:
+ string += "
"
string += line
previous = line
@@ -96,7 +96,11 @@ class Formater(CommonFormater):
"""Display a liste of element"""
prefix = "