feat: could not change default value during annotator
This commit is contained in:
parent
02778fe53b
commit
2a7f78103b
3 changed files with 49 additions and 58 deletions
|
|
@ -53,28 +53,32 @@ class Annotator(Walk):
|
|||
if not objectspace.paths:
|
||||
return
|
||||
self.objectspace = objectspace
|
||||
self.change_default_value = self.objectspace.rougailconfig["doc.change_default_value"]
|
||||
self.populate_family()
|
||||
self.populate_variable()
|
||||
|
||||
def populate_family(self) -> None:
|
||||
"""Set doc, path, ... to family"""
|
||||
for family in self.get_families():
|
||||
self.convert_variable_property(family)
|
||||
if family.type != "dynamic":
|
||||
continue
|
||||
self.convert_property(family)
|
||||
if family.type == "dynamic":
|
||||
self.populate_family_dynamic(family)
|
||||
|
||||
def populate_family_dynamic(self, family) -> None:
|
||||
if self.change_default_value:
|
||||
if not isinstance(family.dynamic, list):
|
||||
self.dynamic_values(family, family.dynamic)
|
||||
self.force_default_value_in_suffix_variable(family, family.dynamic)
|
||||
else:
|
||||
for value in family.dynamic:
|
||||
self.dynamic_values(family, value, return_a_list=False)
|
||||
self.calculation_to_information(
|
||||
family.path,
|
||||
"dynamic",
|
||||
family.dynamic,
|
||||
family.version,
|
||||
)
|
||||
self.force_default_value_in_suffix_variable(family, value, return_a_list=False)
|
||||
self.calculation_to_information(
|
||||
family.path,
|
||||
"dynamic",
|
||||
family.dynamic,
|
||||
family.version,
|
||||
)
|
||||
|
||||
def dynamic_values(
|
||||
def force_default_value_in_suffix_variable(
|
||||
self,
|
||||
family,
|
||||
value,
|
||||
|
|
@ -145,11 +149,11 @@ class Annotator(Walk):
|
|||
variable.validators,
|
||||
variable.version,
|
||||
)
|
||||
if variable.path in self.objectspace.leaders and not default:
|
||||
if self.change_default_value and variable.path in self.objectspace.leaders and not default:
|
||||
self.add_examples_values(variable)
|
||||
self.convert_variable_property(variable)
|
||||
self.convert_property(variable)
|
||||
|
||||
def convert_variable_property(
|
||||
def convert_property(
|
||||
self,
|
||||
variable: dict,
|
||||
) -> None:
|
||||
|
|
@ -173,46 +177,29 @@ class Annotator(Walk):
|
|||
version: str,
|
||||
):
|
||||
"""tranform calculation to an information"""
|
||||
one_is_calculation = False
|
||||
if not isinstance(values, list):
|
||||
if not isinstance(values, Calculation):
|
||||
return
|
||||
self._calculation_to_information(
|
||||
path,
|
||||
prop,
|
||||
self._calculation_to_string(path, prop, values, version),
|
||||
)
|
||||
one_is_calculation = True
|
||||
datas = self.calculation_to_string(path, prop, values, version)
|
||||
else:
|
||||
datas = []
|
||||
one_is_calculation = False
|
||||
for idx, val in enumerate(values):
|
||||
data = self._calculation_to_string(path, prop, val, version)
|
||||
data = self.calculation_to_string(path, prop, val, version)
|
||||
if data is None:
|
||||
continue
|
||||
if "type" in data or "description" in data:
|
||||
one_is_calculation = True
|
||||
datas.append(data)
|
||||
if one_is_calculation:
|
||||
self._calculation_to_information(
|
||||
path,
|
||||
prop,
|
||||
datas,
|
||||
)
|
||||
if one_is_calculation:
|
||||
self.objectspace.informations.add(
|
||||
path,
|
||||
f"{prop}_calculation",
|
||||
datas,
|
||||
)
|
||||
|
||||
def _calculation_to_information(
|
||||
self,
|
||||
path: str,
|
||||
prop: str,
|
||||
datas: Union[dict, list[dict]],
|
||||
) -> None:
|
||||
if datas is None:
|
||||
return
|
||||
self.objectspace.informations.add(
|
||||
path,
|
||||
f"{prop}_calculation",
|
||||
datas,
|
||||
)
|
||||
|
||||
def _calculation_to_string(
|
||||
def calculation_to_string(
|
||||
self,
|
||||
path: str,
|
||||
prop: str,
|
||||
|
|
@ -224,13 +211,17 @@ class Annotator(Walk):
|
|||
if values.description:
|
||||
return {"description": values.description}
|
||||
if isinstance(values, JinjaCalculation):
|
||||
if values.description:
|
||||
value = values.description
|
||||
else:
|
||||
value = True
|
||||
return {
|
||||
"type": "jinja",
|
||||
"value": self._calculation_to_information_jinja(values),
|
||||
"value": value,
|
||||
}
|
||||
if isinstance(values, (VariableCalculation, VariablePropertyCalculation)):
|
||||
variable_path = self._get_path_from_variable(values, version, path)
|
||||
value = self._calculation_to_information_variable(
|
||||
variable_path = self.get_path_from_variable(values, version, path)
|
||||
value = self.calculation_to_information_variable(
|
||||
variable_path, values, prop, version, path
|
||||
)
|
||||
if value is None:
|
||||
|
|
@ -243,14 +234,14 @@ class Annotator(Walk):
|
|||
if isinstance(values, InformationCalculation):
|
||||
return {
|
||||
"type": "information",
|
||||
"value": self._calculation_to_information_information(
|
||||
"value": self.calculation_to_information_information(
|
||||
values, version, path
|
||||
),
|
||||
}
|
||||
if isinstance(values, (IdentifierCalculation, IdentifierPropertyCalculation)):
|
||||
return {
|
||||
"type": "identifier",
|
||||
"value": self._calculation_to_information_identifier(
|
||||
"value": self.calculation_to_information_identifier(
|
||||
values, prop, version
|
||||
),
|
||||
}
|
||||
|
|
@ -266,12 +257,7 @@ class Annotator(Walk):
|
|||
}
|
||||
raise Exception(f'unknown calculation {type(values)} "{values}"')
|
||||
|
||||
def _calculation_to_information_jinja(self, values):
|
||||
if values.description:
|
||||
return values.description
|
||||
return True
|
||||
|
||||
def _calculation_to_information_variable(
|
||||
def calculation_to_information_variable(
|
||||
self, variable_path: str, values, prop: str, version: str, path: str
|
||||
) -> str:
|
||||
# is optional
|
||||
|
|
@ -305,17 +291,17 @@ class Annotator(Walk):
|
|||
|
||||
return values_calculation
|
||||
|
||||
def _calculation_to_information_information(
|
||||
def calculation_to_information_information(
|
||||
self, values, version: str, path: str
|
||||
) -> Union[str, bool]:
|
||||
if values.variable:
|
||||
variable_path = self._get_path_from_variable(values, version, path)
|
||||
variable_path = self.get_path_from_variable(values, version, path)
|
||||
return _('the value of the information "{0}" of the variable "{1}"').format(
|
||||
values.information, variable_path
|
||||
)
|
||||
return _('the value of the global information "{0}"').format(values.information)
|
||||
|
||||
def _calculation_to_information_identifier(
|
||||
def calculation_to_information_identifier(
|
||||
self, values, prop: str, version: str
|
||||
) -> Union[str, bool]:
|
||||
if version != "1.0" and prop in PROPERTY_ATTRIBUTE:
|
||||
|
|
@ -325,7 +311,7 @@ class Annotator(Walk):
|
|||
return _('when the identifier is not "{0}"').format(values.when_not)
|
||||
return True
|
||||
|
||||
def _get_path_from_variable(self, values, version: str, path: str) -> str:
|
||||
def get_path_from_variable(self, values, version: str, path: str) -> str:
|
||||
variable_path = values.variable
|
||||
paths = self.objectspace.paths
|
||||
if version != "1.0" and paths.regexp_relative.search(variable_path):
|
||||
|
|
|
|||
|
|
@ -109,6 +109,10 @@ doc:
|
|||
{{% endif %}}
|
||||
description: {_('verify if disable modes already exists')}
|
||||
|
||||
change_default_value:
|
||||
description: {_('Modify values to document leaderships and dynamics families')}
|
||||
default: true
|
||||
|
||||
output_format:
|
||||
description: {_('Generate document in format')}
|
||||
alternative_name: do
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ def test_force_optional():
|
|||
dirs = [str(test_dir / 'force_optional')]
|
||||
rougailconfig['main_dictionaries'] = dirs
|
||||
rougailconfig['doc.output_format'] = 'asciidoc'
|
||||
rougailconfig['doc.change_default_value'] = True
|
||||
rougail = Rougail(rougailconfig)
|
||||
config = rougail.run()
|
||||
inventory = RougailOutputDoc(config, rougailconfig=rougailconfig)
|
||||
|
|
|
|||
Loading…
Reference in a new issue