fix: calculation for dynamic ans leadership variables

This commit is contained in:
egarette@silique.fr 2025-04-05 11:23:47 +02:00
parent b4dfa14602
commit a7ede66aa7
28 changed files with 289 additions and 62 deletions

View file

@ -88,7 +88,7 @@ class Annotator(Walk):
"""For dynamic we must have values to document it""" """For dynamic we must have values to document it"""
if not isinstance(value, Calculation): if not isinstance(value, Calculation):
return return
default_values = ["example"] value_added = False
if isinstance(value, (VariableCalculation, VariablePropertyCalculation)): if isinstance(value, (VariableCalculation, VariablePropertyCalculation)):
variable = self.objectspace.paths.get_with_dynamic( variable = self.objectspace.paths.get_with_dynamic(
value.variable, value.variable,
@ -97,21 +97,29 @@ class Annotator(Walk):
value.namespace, value.namespace,
value.xmlfiles, value.xmlfiles,
)[0] )[0]
if variable: if variable and not variable.default:
values = self.get_examples_values(variable) values = self.add_examples_values(variable)
if values: value_added = True
default_values = values if not value_added:
if not return_a_list: default_values = ["example"]
default_values = default_values[0] if not return_a_list:
value.default_values = default_values default_values = default_values[0]
value.default_values = default_values
def get_examples_values(self, variable) -> list: def add_examples_values(self, variable) -> list:
"""Check examples or test information to define examples values""" """Check examples or test information to define examples values in a variable"""
values = self.objectspace.informations.get(variable.path).get("examples", None) values = self.objectspace.informations.get(variable.path).get("examples", None)
if not values: if not values:
values = self.objectspace.informations.get(variable.path).get("test", None) values = self.objectspace.informations.get(variable.path).get("test", None)
if isinstance(values, tuple): if isinstance(values, tuple):
values = list(values) values = list(values)
if values:
variable.default = list(values)
else:
variable.default = [CONVERT_OPTION[variable.type]["example"]]
self.objectspace.informations.add(
variable.path, "default_value_makes_sense", False
)
return values return values
def populate_variable(self) -> None: def populate_variable(self) -> None:
@ -139,14 +147,7 @@ class Annotator(Walk):
variable.version, variable.version,
) )
if variable.path in self.objectspace.leaders and not variable.default: if variable.path in self.objectspace.leaders and not variable.default:
values = self.get_examples_values(variable) self.add_examples_values(variable)
if values:
variable.default = list(values)
else:
variable.default = [CONVERT_OPTION[variable.type]["example"]]
self.objectspace.informations.add(
variable.path, "default_value_makes_sense", False
)
self.objectspace.informations.add( self.objectspace.informations.add(
variable.path, "dictionaries", variable.xmlfiles variable.path, "dictionaries", variable.xmlfiles
) )

View file

@ -375,7 +375,7 @@ 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 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")
@ -510,14 +510,13 @@ class RougailOutputDoc(Examples):
self, self,
variable, variable,
): ):
if not variable.information.get("default_value_makes_sense", True):
return None
default = self._to_string(variable, "default", do_not_raise=True) default = self._to_string(variable, "default", do_not_raise=True)
if default is not None: if default is not None:
if default == []: if default == []:
default = None default = None
return default return default
default = variable.value.get(uncalculated=True) if variable.information.get("default_value_makes_sense", True):
default = variable.value.get(uncalculated=True)
if default == []: if default == []:
default = None default = None
return default return default
@ -526,11 +525,8 @@ class RougailOutputDoc(Examples):
self, self,
variable, variable,
prop, prop,
identifier="",
do_not_raise=False, do_not_raise=False,
): ):
if identifier:
raise Exception("pfff")
calculation = variable.information.get(f"{prop}_calculation", None) calculation = variable.information.get(f"{prop}_calculation", None)
if not calculation: if not calculation:
if do_not_raise: if do_not_raise:

View file

@ -1,3 +1,12 @@
# Example with mandatory variables not filled in
```yaml
---
leader:
- leader: example
follower1: example
follower2: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,12 @@
# Example with mandatory variables not filled in
```yaml
---
leadership:
- leader: example
follower1: example
follower2: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,10 @@
# Example with mandatory variables not filled in
```yaml
---
leader:
- leader: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
general1:
leader:
- leader: example
follower1: example
follower2: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
leader:
- leader: example
follower1: example
follower2: example
follower3: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,12 @@
# Example with mandatory variables not filled in
```yaml
---
leadership:
- leader: example
follower1:
- example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,10 @@
# Example with mandatory variables not filled in
```yaml
---
leader:
- leader: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,11 @@
# Example with mandatory variables not filled in
```yaml
---
leader:
- leader: example
follower: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
dynval1:
leadership:
- leader: example
dynval2:
leadership:
- leader: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
dynval1:
leadership:
- leader: example
dynval2:
leadership:
- leader: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -47,22 +47,28 @@ This family builds families dynamically.
| Variable | Description | Variable | Description
| |
**rougail.dyn__val1__.dyn___example__.var** + **rougail.dyn__val1__.dyn___tval1__.var** +
**rougail.dyn__val2__.dyn___example__.var** + **rougail.dyn__val1__.dyn___tval2__.var** +
**rougail.dyn__val2__.dyn___tval1__.var** +
**rougail.dyn__val2__.dyn___tval2__.var** +
`https://rougail.readthedocs.io/en/latest/variable.html#variables-types[string]` `standard` `mandatory` | `https://rougail.readthedocs.io/en/latest/variable.html#variables-types[string]` `standard` `mandatory` |
A variable dynamic. + A variable dynamic. +
**Default**: the value of the identifier. **Default**: the value of the identifier.
| |
**rougail.dyn__val1__.dyn___example__.var_identifier** + **rougail.dyn__val1__.dyn___tval1__.var_identifier** +
**rougail.dyn__val2__.dyn___example__.var_identifier** + **rougail.dyn__val1__.dyn___tval2__.var_identifier** +
**rougail.dyn__val2__.dyn___tval1__.var_identifier** +
**rougail.dyn__val2__.dyn___tval2__.var_identifier** +
`https://rougail.readthedocs.io/en/latest/variable.html#variables-types[string]` `standard` `mandatory` | `https://rougail.readthedocs.io/en/latest/variable.html#variables-types[string]` `standard` `mandatory` |
Identifier from first family. + Identifier from first family. +
**Default**: the value of the identifier. **Default**: the value of the identifier.
| |
**rougail.dyn__val1__.dyn___example__.var_identifiers** + **rougail.dyn__val1__.dyn___tval1__.var_identifiers** +
**rougail.dyn__val2__.dyn___example__.var_identifiers** + **rougail.dyn__val1__.dyn___tval2__.var_identifiers** +
**rougail.dyn__val2__.dyn___tval1__.var_identifiers** +
**rougail.dyn__val2__.dyn___tval2__.var_identifiers** +
`https://rougail.readthedocs.io/en/latest/variable.html#variables-types[string]` `standard` `mandatory` | `https://rougail.readthedocs.io/en/latest/variable.html#variables-types[string]` `standard` `mandatory` |
Merge identifiers. + Merge identifiers. +
**Default**: join identifier 1 et identifier 2. **Default**: join identifier 1 et identifier 2.

View file

@ -116,12 +116,16 @@
"type": "dynamic", "type": "dynamic",
"informations": { "informations": {
"paths": [ "paths": [
"rougail.dynval1.dyn_example", "rougail.dynval1.dyn_tval1",
"rougail.dynval2.dyn_example" "rougail.dynval1.dyn_tval2",
"rougail.dynval2.dyn_tval1",
"rougail.dynval2.dyn_tval2"
], ],
"names": [ "names": [
"dyn_example", "dyn_tval1",
"dyn_example" "dyn_tval2",
"dyn_tval1",
"dyn_tval2"
], ],
"description": "a Second dynamic variable", "description": "a Second dynamic variable",
"properties": [ "properties": [
@ -138,10 +142,14 @@
"children": { "children": {
"rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var": { "rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var": {
"paths": [ "paths": [
"rougail.dynval1.dyn_example.var", "rougail.dynval1.dyn_tval1.var",
"rougail.dynval2.dyn_example.var" "rougail.dynval1.dyn_tval2.var",
"rougail.dynval2.dyn_tval1.var",
"rougail.dynval2.dyn_tval2.var"
], ],
"names": [ "names": [
"var",
"var",
"var", "var",
"var" "var"
], ],
@ -167,10 +175,14 @@
}, },
"rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifier": { "rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifier": {
"paths": [ "paths": [
"rougail.dynval1.dyn_example.var_identifier", "rougail.dynval1.dyn_tval1.var_identifier",
"rougail.dynval2.dyn_example.var_identifier" "rougail.dynval1.dyn_tval2.var_identifier",
"rougail.dynval2.dyn_tval1.var_identifier",
"rougail.dynval2.dyn_tval2.var_identifier"
], ],
"names": [ "names": [
"var_identifier",
"var_identifier",
"var_identifier", "var_identifier",
"var_identifier" "var_identifier"
], ],
@ -196,10 +208,14 @@
}, },
"rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers": { "rougail.dyn{{ identifier }}.dyn_{{ identifier }}.var_identifiers": {
"paths": [ "paths": [
"rougail.dynval1.dyn_example.var_identifiers", "rougail.dynval1.dyn_tval1.var_identifiers",
"rougail.dynval2.dyn_example.var_identifiers" "rougail.dynval1.dyn_tval2.var_identifiers",
"rougail.dynval2.dyn_tval1.var_identifiers",
"rougail.dynval2.dyn_tval2.var_identifiers"
], ],
"names": [ "names": [
"var_identifiers",
"var_identifiers",
"var_identifiers", "var_identifiers",
"var_identifiers" "var_identifiers"
], ],

View file

@ -26,7 +26,7 @@ This family builds families dynamically.
| Variable                                                                                                                       | Description                                                                                                                    | | Variable                                                                                                                       | Description                                                                                                                    |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **rougail.dyn*val1*.dyn_*example*.var**<br/>**rougail.dyn*val2*.dyn_*example*.var**<br/>[`string`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `standard` `mandatory` | A variable dynamic.<br/>**Default**: the value of the identifier. | | **rougail.dyn*val1*.dyn_*tval1*.var**<br/>**rougail.dyn*val1*.dyn_*tval2*.var**<br/>**rougail.dyn*val2*.dyn_*tval1*.var**<br/>**rougail.dyn*val2*.dyn_*tval2*.var**<br/>[`string`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `standard` `mandatory` | A variable dynamic.<br/>**Default**: the value of the identifier. |
| **rougail.dyn*val1*.dyn_*example*.var_identifier**<br/>**rougail.dyn*val2*.dyn_*example*.var_identifier**<br/>[`string`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `standard` `mandatory` | Identifier from first family.<br/>**Default**: the value of the identifier. | | **rougail.dyn*val1*.dyn_*tval1*.var_identifier**<br/>**rougail.dyn*val1*.dyn_*tval2*.var_identifier**<br/>**rougail.dyn*val2*.dyn_*tval1*.var_identifier**<br/>**rougail.dyn*val2*.dyn_*tval2*.var_identifier**<br/>[`string`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `standard` `mandatory` | Identifier from first family.<br/>**Default**: the value of the identifier. |
| **rougail.dyn*val1*.dyn_*example*.var_identifiers**<br/>**rougail.dyn*val2*.dyn_*example*.var_identifiers**<br/>[`string`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `standard` `mandatory` | Merge identifiers.<br/>**Default**: join identifier 1 et identifier 2. | | **rougail.dyn*val1*.dyn_*tval1*.var_identifiers**<br/>**rougail.dyn*val1*.dyn_*tval2*.var_identifiers**<br/>**rougail.dyn*val2*.dyn_*tval1*.var_identifiers**<br/>**rougail.dyn*val2*.dyn_*tval2*.var_identifiers**<br/>[`string`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `standard` `mandatory` | Merge identifiers.<br/>**Default**: join identifier 1 et identifier 2. |

View file

@ -50,15 +50,21 @@ This family builds families dynamically.
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
 Variable  ┃ Description  ┃  Variable  ┃ Description  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
rougail.dynval1.dyn_example.var │ A variable dynamic. │ rougail.dynval1.dyn_tval1.var │ A variable dynamic. │
rougail.dynval2.dyn_example.var │ Default: the value of the │ rougail.dynval1.dyn_tval2.var │ Default: the value of the │
 string   standard   mandatory  │ identifier. │ rougail.dynval2.dyn_tval1.var │ identifier. │
rougail.dynval2.dyn_tval2.var │ │
 string   standard   mandatory  │ │
├───────────────────────────────────────┼──────────────────────────────────────┤ ├───────────────────────────────────────┼──────────────────────────────────────┤
rougail.dynval1.dyn_example.var_iden… │ Identifier from first family. │ rougail.dynval1.dyn_tval1.var_identi… │ Identifier from first family. │
rougail.dynval2.dyn_example.var_iden… │ Default: the value of the │ rougail.dynval1.dyn_tval2.var_identi… │ Default: the value of the │
 string   standard   mandatory  │ identifier. │ rougail.dynval2.dyn_tval1.var_identi… │ identifier. │
rougail.dynval2.dyn_tval2.var_identi… │ │
 string   standard   mandatory  │ │
├───────────────────────────────────────┼──────────────────────────────────────┤ ├───────────────────────────────────────┼──────────────────────────────────────┤
rougail.dynval1.dyn_example.var_iden… │ Merge identifiers. │ rougail.dynval1.dyn_tval1.var_identi… │ Merge identifiers. │
rougail.dynval2.dyn_example.var_iden… │ Default: join identifier 1 et │ rougail.dynval1.dyn_tval2.var_identi… │ Default: join identifier 1 et │
 string   standard   mandatory  │ identifier 2. │ rougail.dynval2.dyn_tval1.var_identi… │ identifier 2. │
rougail.dynval2.dyn_tval2.var_identi… │ │
 string   standard   mandatory  │ │
└───────────────────────────────────────┴──────────────────────────────────────┘ └───────────────────────────────────────┴──────────────────────────────────────┘

View file

@ -1,3 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
leader:
- leader: example
follower1: example
follower2: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
leadership:
- leader: example
follower1: example
follower2: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,11 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
leader:
- leader: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
general1:
leader:
- leader: example
follower1: example
follower2: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
leader:
- leader: example
follower1: example
follower2: example
follower3: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
leadership:
- leader: example
follower1:
- example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,11 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
leader:
- leader: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,12 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
leader:
- leader: example
follower: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,15 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
dynval1:
leadership:
- leader: example
dynval2:
leadership:
- leader: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -1,3 +1,15 @@
# Example with mandatory variables not filled in
```yaml
---
rougail:
dynval1:
leadership:
- leader: example
dynval2:
leadership:
- leader: example
```
# Example with all variables modifiable # Example with all variables modifiable
```yaml ```yaml

View file

@ -8,16 +8,26 @@ rougail:
- val2 - val2
dynval1: dynval1:
var: var:
- example - tval1
dyn_example: - tval2
var: example dyn_tval1:
var: tval1
var_identifier: val1 var_identifier: val1
var_identifiers: val1-example var_identifiers: val1-tval1
dyn_tval2:
var: tval2
var_identifier: val1
var_identifiers: val1-tval2
dynval2: dynval2:
var: var:
- example - tval1
dyn_example: - tval2
var: example dyn_tval1:
var: tval1
var_identifier: val2 var_identifier: val2
var_identifiers: val2-example var_identifiers: val2-tval1
dyn_tval2:
var: tval2
var_identifier: val2
var_identifiers: val2-tval2
``` ```

View file

@ -14,7 +14,7 @@ excludes = [
] ]
test_ok = get_structures_list(excludes) test_ok = get_structures_list(excludes)
# test_ok = [Path('../rougail-tests/structures/60_5family_dynamic_calc_suffix_disabled2')] # test_ok = [Path('../rougail-tests/structures/60_0family_dynamic_test')]
os.environ['COLUMNS'] = '80' os.environ['COLUMNS'] = '80'