Quick definition of an optional parameter variable #24
12 changed files with 121 additions and 4 deletions
|
@ -83,8 +83,8 @@ class NotFoundError(Exception):
|
|||
## ---- specific exceptions ----
|
||||
|
||||
class VariableCalculationDependencyError(Exception):
|
||||
"""When an attribute is set, and
|
||||
the target of this attribute doesn't exists.
|
||||
"""When an 'optional=true' attribute is set, and
|
||||
the target variable doesn't exists.
|
||||
"""
|
||||
gremond marked this conversation as resolved
Outdated
|
||||
def __init__(self, msg, errno, xmlfiles):
|
||||
if xmlfiles:
|
||||
|
|
|
@ -429,8 +429,15 @@ class _VariableCalculation(Calculation):
|
|||
needs_multi: Optional[bool] = None,
|
||||
):
|
||||
if not variable:
|
||||
msg = f'Variable not found "{self.variable}" for attribut "{self.attribute_name}" for variable "{self.path}"'
|
||||
if self.optional:
|
||||
msg = f'the dependent variable was not found "{self.optional}" for variable "{self.path}"'
|
||||
raise VariableCalculationDependencyError(msg, 90, self.xmlfiles)
|
||||
else:
|
||||
msg = f'Variable not found "{self.variable}" for attribute "{self.attribute_name}" for variable "{self.path}"'
|
||||
raise DictConsistencyError(msg, 88, self.xmlfiles)
|
||||
if not isinstance(variable, objectspace.variable):
|
||||
# FIXME remove the pfff
|
||||
raise Exception("pfff it's a family")
|
||||
param = {
|
||||
"type": "variable",
|
||||
"variable": variable,
|
||||
|
|
|
@ -478,6 +478,7 @@ class Variable(Common):
|
|||
keys["default"] = self.populate_calculation(self.elt.default)
|
||||
except VariableCalculationDependencyError:
|
||||
pass
|
||||
# mettre dans tous les populate_calculation()
|
||||
if self.elt.path in self.objectspace.default_multi:
|
||||
try:
|
||||
keys["default_multi"] = self.populate_calculation(
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
version: 1.1
|
||||
gremond marked this conversation as resolved
Outdated
gnunux
commented
"---" missing "---" missing
|
||||
#my_variable:
|
||||
# multi: true
|
||||
# default:
|
||||
# - val1
|
||||
# - val2
|
||||
my_calculated_variable:
|
||||
multi: true
|
||||
default:
|
||||
type: variable
|
||||
variable: rougail.my_variable
|
||||
optional: true
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
version: 1.1
|
||||
var1:
|
||||
default:
|
||||
type: jinja
|
||||
jinja: |
|
||||
val
|
||||
params:
|
||||
var1:
|
||||
type: variable
|
||||
variable: _.var2
|
||||
optional: true
|
||||
|
||||
|
||||
---
|
||||
version: 1.1
|
||||
var1:
|
||||
default:
|
||||
type: variable
|
||||
variable: _.var2
|
||||
optional: true
|
||||
|
||||
---
|
||||
<gnunux_recto> le 1er dico fonctionne
|
||||
<gnunux_recto> si on fait une variable dans un parametre on peut la mettre optionnelle (si la variable est déclaré ca passe la variable en parametre, si la variable n'existe pas ca ne passe pas le parametre)
|
||||
<gnunux_recto> dans notre cas la variable n'existe pas donc ne passe pas le parametre
|
||||
<gnunux_recto> dans le 2eme ca on ne fait pas un calcul via jinja mais récupère directement la valeur de la variable
|
||||
<gnunux_recto> sauf que le optional n'existe pas pour un calcul (juste pour un parametre)
|
||||
<gnunux_recto> faudrait :
|
||||
<gnunux_recto> 1/ ajouter cette possibilité
|
||||
<gnunux_recto> voir s'il n'y a pas d'autres manque
|
||||
<gnunux_recto> (c'étaot ele 2)
|
|
@ -0,0 +1,10 @@
|
|||
from tiramisu import *
|
||||
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
|
||||
load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||
option_2 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2], properties=frozenset({"standard"}))
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,14 @@
|
|||
from tiramisu import *
|
||||
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
|
||||
load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||
option_3 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[option_3], properties=frozenset({"standard"}))
|
||||
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||
option_6 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
optiondescription_5 = OptionDescription(name="rougail", doc="rougail", children=[option_6], properties=frozenset({"standard"}))
|
||||
optiondescription_4 = OptionDescription(name="2", doc="2", children=[optiondescription_5], properties=frozenset({"standard"}))
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_4])
|
|
@ -0,0 +1,13 @@
|
|||
version: 1.1
|
||||
gremond marked this conversation as resolved
Outdated
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
gnunux
commented
"---" missing "---" missing
|
||||
my_variable:
|
||||
gnunux
commented
"---" missing "---" missing
|
||||
multi: true
|
||||
default:
|
||||
- val1
|
||||
- val2
|
||||
my_calculated_variable:
|
||||
multi: true
|
||||
default:
|
||||
type: variable
|
||||
variable: rougail.my_variable
|
||||
optional: true
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
from tiramisu import *
|
||||
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
|
||||
load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||
option_2 = StrOption(name="my_variable", doc="my_variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
option_3 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_3], properties=frozenset({"standard"}))
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,16 @@
|
|||
from tiramisu import *
|
||||
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
|
||||
load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||
option_3 = StrOption(name="my_variable", doc="my_variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
option_4 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, default=Calculation(func['calc_value'], Params((ParamOption(option_3)))), properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[option_3, option_4], properties=frozenset({"standard"}))
|
||||
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||
option_7 = StrOption(name="my_variable", doc="my_variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
option_8 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, default=Calculation(func['calc_value'], Params((ParamOption(option_7)))), properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||
optiondescription_6 = OptionDescription(name="rougail", doc="rougail", children=[option_7, option_8], properties=frozenset({"standard"}))
|
||||
optiondescription_5 = OptionDescription(name="2", doc="2", children=[optiondescription_6], properties=frozenset({"standard"}))
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_5])
|
Loading…
Reference in a new issue
This comment should be more generic, maybe in future we will use it for a new attribute.