doc for valid_enum
This commit is contained in:
parent
54bf1c35a7
commit
46ba8c8067
|
@ -1,4 +1,5 @@
|
||||||
# Les vérifications des valeurs
|
# Les vérifications des valeurs
|
||||||
|
|
||||||
- [Fonction de vérification](function.md)
|
- [Fonction de vérification](function.md)
|
||||||
|
- [Les variables à choix](valid_enum.md)
|
||||||
- [Réfinition](redefine.md)
|
- [Réfinition](redefine.md)
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Les variables à choix
|
||||||
|
|
||||||
|
Une variable à choix est d'abord une variable avec une [fonction check](function.md).
|
||||||
|
|
||||||
|
## Les variables à choix simple
|
||||||
|
|
||||||
|
Il est possible d'imposer une liste de valeur pour une variable particulière :
|
||||||
|
|
||||||
|
```
|
||||||
|
<check name="valid_enum">
|
||||||
|
<param>yes</param>
|
||||||
|
<param>no</param>
|
||||||
|
<param>maybe</param>
|
||||||
|
<target>my_variable</target>
|
||||||
|
</check>
|
||||||
|
```
|
||||||
|
|
||||||
|
Dans ce cas, seule les valeurs proposés sont possible pour cette variable.
|
||||||
|
|
||||||
|
Par défaut, cette variable est obligatoire. Cela signifie qu'il n'est pas possible de spécifier "None" à cette variable.
|
||||||
|
|
||||||
|
## Les variables à choix avec valeur None
|
||||||
|
|
||||||
|
Il y a deux possibilités pour avoir une valeur "None" dans les choix :
|
||||||
|
|
||||||
|
- rendre la variable non obligatoire, cela va ajouter un choix "None" dans la liste :
|
||||||
|
|
||||||
|
```
|
||||||
|
<variable name="my_variable" mandatory="False">
|
||||||
|
```
|
||||||
|
|
||||||
|
Ou en ajoutant le paramètre "None" :
|
||||||
|
|
||||||
|
```
|
||||||
|
<check name="valid_enum">
|
||||||
|
<param>yes</param>
|
||||||
|
<param>no</param>
|
||||||
|
<param type='nil'/>
|
||||||
|
<param>maybe</param>
|
||||||
|
<target>my_variable</target>
|
||||||
|
</check>
|
||||||
|
```
|
||||||
|
|
||||||
|
## La valeur par défaut
|
||||||
|
|
||||||
|
Si aucune valeur n'est spécifié pour la variable, automatiquement le premier choix va est placé comme valeur par défaut.
|
|
@ -113,6 +113,9 @@ Les variables booléans sont par défaut obligatoire. Pour qu'une variable bool
|
||||||
<variable name="my_variable" type="boolean" mandatory="False"/>
|
<variable name="my_variable" type="boolean" mandatory="False"/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Les variables avec une valeur par défaut (non calculée) sont également automatiquement obligatoire.
|
||||||
|
[Les variables à choix](../check/valid_enum.md) sans choix "None" sont également automatiquement obligatoire.
|
||||||
|
|
||||||
## Valeur par défaut d'une variable
|
## Valeur par défaut d'une variable
|
||||||
|
|
||||||
Il est possible de fixer les valeurs par défaut d'une variable :
|
Il est possible de fixer les valeurs par défaut d'une variable :
|
||||||
|
|
|
@ -110,7 +110,7 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
|
||||||
# check value
|
# check value
|
||||||
self.check_valid_enum_value(target.name, values)
|
self.check_valid_enum_value(target.name, values)
|
||||||
else:
|
else:
|
||||||
# no value, set the first choice has default value
|
# no value, set the first choice as default value
|
||||||
new_value = self.objectspace.value(check.xmlfiles)
|
new_value = self.objectspace.value(check.xmlfiles)
|
||||||
new_value.name = values[0]
|
new_value.name = values[0]
|
||||||
new_value.type = variable_type
|
new_value.type = variable_type
|
||||||
|
@ -124,8 +124,6 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
|
||||||
variable,
|
variable,
|
||||||
check,
|
check,
|
||||||
) -> List[Any]:
|
) -> List[Any]:
|
||||||
# value for choice's variable is mandatory
|
|
||||||
variable.mandatory = True
|
|
||||||
# build choice
|
# build choice
|
||||||
variable.values = []
|
variable.values = []
|
||||||
variable.ori_type = variable.type
|
variable.ori_type = variable.type
|
||||||
|
@ -133,6 +131,7 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
|
||||||
|
|
||||||
has_variable = False
|
has_variable = False
|
||||||
values = []
|
values = []
|
||||||
|
has_nil = False
|
||||||
for param in check.param:
|
for param in check.param:
|
||||||
if has_variable:
|
if has_variable:
|
||||||
msg = _(f'only one "variable" parameter is allowed for valid_enum '
|
msg = _(f'only one "variable" parameter is allowed for valid_enum '
|
||||||
|
@ -150,15 +149,22 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
|
||||||
f'of variable "{variable.name}"')
|
f'of variable "{variable.name}"')
|
||||||
raise DictConsistencyError(msg, 6, param.xmlfiles)
|
raise DictConsistencyError(msg, 6, param.xmlfiles)
|
||||||
param_type = 'calculation'
|
param_type = 'calculation'
|
||||||
|
elif param.type == 'nil':
|
||||||
|
has_nil = True
|
||||||
values.append(param.text)
|
values.append(param.text)
|
||||||
choice = self.objectspace.choice(variable.xmlfiles)
|
choice = self.objectspace.choice(variable.xmlfiles)
|
||||||
choice.name = param.text
|
choice.name = param.text
|
||||||
choice.type = param_type
|
choice.type = param_type
|
||||||
variable.values.append(choice)
|
variable.values.append(choice)
|
||||||
|
if 'mandatory' not in vars(variable):
|
||||||
|
variable.mandatory = not has_nil
|
||||||
|
elif variable.mandatory is False:
|
||||||
|
choice = self.objectspace.choice(variable.xmlfiles)
|
||||||
|
choice.name = None
|
||||||
|
choice.type = 'nil'
|
||||||
|
variable.values.append(choice)
|
||||||
if has_variable:
|
if has_variable:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for target in check.target:
|
for target in check.target:
|
||||||
self.objectspace.valid_enums[target.name.path] = {'type': variable.ori_type,
|
self.objectspace.valid_enums[target.name.path] = {'type': variable.ori_type,
|
||||||
'values': values,
|
'values': values,
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail version="0.9">
|
||||||
|
<variables>
|
||||||
|
<family name="general" mode="expert">
|
||||||
|
<variable name="mode_conteneur_actif" type="string" description="No change">
|
||||||
|
<value>non</value>
|
||||||
|
</variable>
|
||||||
|
</family>
|
||||||
|
<family name="enumfam" mode="expert">
|
||||||
|
<variable name="enumvar" mandatory="False">
|
||||||
|
<value>c</value>
|
||||||
|
</variable>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<check name="valid_enum">
|
||||||
|
<param>a</param>
|
||||||
|
<param>b</param>
|
||||||
|
<param>c</param>
|
||||||
|
<target>enumvar</target>
|
||||||
|
</check>
|
||||||
|
</constraints>
|
||||||
|
</rougail>
|
||||||
|
<!-- vim: ts=4 sw=4 expandtab
|
||||||
|
-->
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.general.mode_conteneur_actif": "non",
|
||||||
|
"rougail.enumfam.enumvar": "c"
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
from importlib.machinery import SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader, module_from_spec
|
||||||
|
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py')
|
||||||
|
spec = spec_from_loader(loader.name, loader)
|
||||||
|
func = module_from_spec(spec)
|
||||||
|
loader.exec_module(func)
|
||||||
|
for key, value in dict(locals()).items():
|
||||||
|
if key != ['SourceFileLoader', 'func']:
|
||||||
|
setattr(func, key, value)
|
||||||
|
try:
|
||||||
|
from tiramisu3 import *
|
||||||
|
except:
|
||||||
|
from tiramisu import *
|
||||||
|
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
|
||||||
|
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
|
||||||
|
option_5 = ChoiceOption(name="enumvar", doc="enumvar", values=('a', 'b', 'c', None), default="c", properties=frozenset({"expert"}))
|
||||||
|
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
|
||||||
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])
|
|
@ -7,7 +7,7 @@
|
||||||
</variable>
|
</variable>
|
||||||
</family>
|
</family>
|
||||||
<family name="enumfam" mode="expert">
|
<family name="enumfam" mode="expert">
|
||||||
<variable name="enumvar" type="string" description="multi" help="bla bla bla">
|
<variable name="enumvar" type="string" description="multi" help="bla bla bla" mandatory="False">
|
||||||
<value>b</value>
|
<value>b</value>
|
||||||
</variable>
|
</variable>
|
||||||
</family>
|
</family>
|
||||||
|
@ -17,7 +17,6 @@
|
||||||
<check name="valid_enum">
|
<check name="valid_enum">
|
||||||
<param>a</param>
|
<param>a</param>
|
||||||
<param>b</param>
|
<param>b</param>
|
||||||
<param type="nil"/>
|
|
||||||
<param></param>
|
<param></param>
|
||||||
<target>enumvar</target>
|
<target>enumvar</target>
|
||||||
</check>
|
</check>
|
||||||
|
|
|
@ -13,7 +13,7 @@ except:
|
||||||
from tiramisu import *
|
from tiramisu import *
|
||||||
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
|
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
|
||||||
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
|
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
|
||||||
option_5 = ChoiceOption(name="enumvar", doc="multi", values=('a', 'b', None, ''), default="b", properties=frozenset({"expert", "mandatory"}))
|
option_5 = ChoiceOption(name="enumvar", doc="multi", values=('a', 'b', '', None), default="b", properties=frozenset({"expert"}))
|
||||||
option_5.impl_set_information('help', "bla bla bla")
|
option_5.impl_set_information('help', "bla bla bla")
|
||||||
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
|
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
|
||||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
|
||||||
|
|
|
@ -13,7 +13,7 @@ except:
|
||||||
from tiramisu import *
|
from tiramisu import *
|
||||||
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
|
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
|
||||||
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
|
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
|
||||||
option_5 = ChoiceOption(name="enumvar", doc="multi", values=(None,), properties=frozenset({"expert", "mandatory"}))
|
option_5 = ChoiceOption(name="enumvar", doc="multi", values=(None,), properties=frozenset({"expert"}))
|
||||||
option_5.impl_set_information('help', "bla bla bla")
|
option_5.impl_set_information('help', "bla bla bla")
|
||||||
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
|
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
|
||||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
|
||||||
|
|
|
@ -13,7 +13,7 @@ except:
|
||||||
from tiramisu import *
|
from tiramisu import *
|
||||||
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
|
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
|
||||||
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
|
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
|
||||||
option_5 = ChoiceOption(name="enumvar", doc="multi", values=(None,), properties=frozenset({"expert", "mandatory"}))
|
option_5 = ChoiceOption(name="enumvar", doc="multi", values=(None,), properties=frozenset({"expert"}))
|
||||||
option_5.impl_set_information('help', "bla bla bla")
|
option_5.impl_set_information('help', "bla bla bla")
|
||||||
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
|
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
|
||||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
|
||||||
|
|
Loading…
Reference in New Issue