Quick definition of an optional parameter variable #24

Merged
egarette merged 8 commits from optional_parameter_in_variable into develop 2024-09-04 17:30:38 +02:00
13 changed files with 14 additions and 269 deletions
Showing only changes of commit 4027aebf96 - Show all commits

View file

@ -428,12 +428,8 @@ class _VariableCalculation(Calculation):
needs_multi: Optional[bool] = None,
):
if not variable:
if self.optional:
msg = f'the dependent variable was not found "{self.optional}" for variable "{self.path}"'
raise VariableCalculationDependencyError(msg, 90, self.xmlfiles)
if not isinstance(variable, objectspace.variable):
# FIXME remove the pfff
raise Exception("pfff it's a family")
msg = f'Variable not found "{self.variable}" for attribut "{self.attribute_name}" for variable "{self.path}"'
raise DictConsistencyError(msg, 88, self.xmlfiles)
param = {
"type": "variable",
"variable": variable,
@ -490,11 +486,17 @@ class VariableCalculation(_VariableCalculation):
self,
objectspace,
) -> dict:
params = self.get_params(objectspace)
if self.attribute_name == "choices":
if hasattr(self, "optional") and self.optional is True:
msg = "'choices' variable shall not have an 'optional' atttibute"
raise DictConsistencyError(msg, 33, self.xmlfiles)
if self.attribute_name != "default" and self.optional is True:
msg = f'"{self.attribute_name}" variable shall not have an "optional" attribute for variable "{self.variable}"'
raise DictConsistencyError(msg, 33, self.xmlfiles)
variable, suffix = self.get_variable(objectspace)
if not variable and self.optional:
msg = f'the dependent variable was not found "{self.optional}" for attribute "{self.attribute_name}" in variable "{self.path}"'
raise VariableCalculationDependencyError(msg, 90, self.xmlfiles)
params = self.get_params(objectspace,
variable,
suffix,
)
return {
"function": "calc_value",
"params": params,

View file

@ -478,13 +478,6 @@ class Variable(Common):
keys["default"] = self.populate_calculation(self.elt.default)
except VariableCalculationDependencyError:
pass
# for attribute in ["frozen", "hidden", "mandatory", "disabled"]:
# if hasattr(self.elt, attribute): # FIXME FIXME and attribute == "optional":
# raise DictConsistencyError(
# f"Sub-attributes not allowed in a '{attribute}' attribute",
# 100,
# self.elt.xmlfiles,
# )
if self.elt.path in self.objectspace.default_multi:
try:
keys["default_multi"] = self.populate_calculation(

View file

@ -5,6 +5,7 @@ varname:
- val1
dyn{{ suffix }}:
dynamic:
type: variable
variable: _.varname
optional: true
vardyn:

View file

@ -1,14 +0,0 @@
---
version: 1.1
#my_variable:
# multi: true
# default:
# - val1
# - val2
my_calculated_variable:
multi: true
default:
type: variable
variable: rougail.my_variable
optional: true

View file

@ -1,24 +0,0 @@
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"}),
informations={"type": "string"},
)
optiondescription_1 = OptionDescription(
name="rougail",
doc="Rougail",
children=[option_2],
properties=frozenset({"standard"}),
)
option_0 = OptionDescription(
name="baseoption", doc="baseoption", children=[optiondescription_1]
)

View file

@ -1,51 +0,0 @@
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"}),
informations={"type": "string"},
)
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"}),
informations={"type": "string"},
)
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],
)

View file

@ -1,16 +0,0 @@
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_1 = StrOption(
name="my_calculated_variable",
doc="my_calculated_variable",
multi=True,
properties=frozenset({"mandatory", "notempty", "standard"}),
informations={"type": "string"},
)
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -1,14 +0,0 @@
---
version: 1.1
my_variable:
multi: true
default:
- val1
- val2
my_calculated_variable:
multi: true
default:
type: variable
variable: rougail.my_variable
optional: true

View file

@ -1,34 +0,0 @@
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"}),
informations={"type": "string"},
)
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"}),
informations={"type": "string"},
)
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]
)

View file

@ -1,71 +0,0 @@
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"}),
informations={"type": "string"},
)
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"}),
informations={"type": "string"},
)
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"}),
informations={"type": "string"},
)
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"}),
informations={"type": "string"},
)
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],
)

View file

@ -1,27 +0,0 @@
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_1 = StrOption(
name="my_variable",
doc="my_variable",
multi=True,
default=["val1", "val2"],
default_multi="val1",
properties=frozenset({"mandatory", "notempty", "standard"}),
informations={"type": "string"},
)
option_2 = StrOption(
name="my_calculated_variable",
doc="my_calculated_variable",
multi=True,
properties=frozenset({"mandatory", "notempty", "standard"}),
informations={"type": "string"},
)
option_0 = OptionDescription(
name="baseoption", doc="baseoption", children=[option_1, option_2]
)