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