feat: add relative path support
This commit is contained in:
parent
59d12a3624
commit
13aedef773
114 changed files with 2695 additions and 572 deletions
105
docs/fill.rst
105
docs/fill.rst
|
@ -156,6 +156,87 @@ There are two types of parameter:
|
||||||
- Name of the information whose value we want to retrieve.
|
- Name of the information whose value we want to retrieve.
|
||||||
- doc
|
- doc
|
||||||
|
|
||||||
|
The variable path
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
Normal family
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The default namespace is defined in RougailConfig["variable_namespace"] with the default value "rougail".
|
||||||
|
In addition, there are extras namespaces defined with in RougailConfig["extra_dictionaries"].
|
||||||
|
|
||||||
|
Inside those namespaces we can add families and variables.
|
||||||
|
|
||||||
|
Here is an hierarchic examples:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
rougail
|
||||||
|
├── variable1
|
||||||
|
├── family1
|
||||||
|
│ ├── variable2
|
||||||
|
│ └── variable3
|
||||||
|
└── family2
|
||||||
|
└── subfamily1
|
||||||
|
└── variable4
|
||||||
|
extra1
|
||||||
|
└── family3
|
||||||
|
├── variable5
|
||||||
|
└── variable6
|
||||||
|
|
||||||
|
In `calculation` we can use other variables.
|
||||||
|
|
||||||
|
Here is all paths:
|
||||||
|
|
||||||
|
- rougail.variable1
|
||||||
|
- rougail.family1.variable2
|
||||||
|
- rougail.family1.variable3
|
||||||
|
- rougail.family2.subfamily1.variable4
|
||||||
|
- extra1.family3.variable5
|
||||||
|
- extra1.family3.variable6
|
||||||
|
|
||||||
|
Inside a variable's `calculation` we can use relative path. "_" means that other variable is in same family. "__" means that other variables are in parent family, and so on...
|
||||||
|
|
||||||
|
For example, in variable2's `calculation`, we can use relative path:
|
||||||
|
|
||||||
|
- __.variable1
|
||||||
|
- _.variable3
|
||||||
|
- __.family2.subfamily1.variable4
|
||||||
|
|
||||||
|
But we cannot access to extra1 variables with relative path.
|
||||||
|
|
||||||
|
Dynamic family
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Hire is a dynamic family "{{ suffix }}":
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
rougail
|
||||||
|
├── variable1: ["val1", "val2"]
|
||||||
|
├── {{ suffix }}
|
||||||
|
│ ├── variable2
|
||||||
|
│ └── variable3
|
||||||
|
└── family
|
||||||
|
└── variable4
|
||||||
|
|
||||||
|
For variable2's calculation, we can use:
|
||||||
|
|
||||||
|
- rougail.{{ suffix }}.variable3
|
||||||
|
- _.variable3
|
||||||
|
|
||||||
|
In this case, we get value for "variable3" with the same suffix as "variable2".
|
||||||
|
|
||||||
|
For variable4's calculation, we have two possibility:
|
||||||
|
|
||||||
|
- retrieves all values with all suffixes:
|
||||||
|
|
||||||
|
- rougail.{{ suffix }}.variable3
|
||||||
|
- __.{{ suffix }}.variable3
|
||||||
|
|
||||||
|
- retrieves a value for a specified suffix:
|
||||||
|
|
||||||
|
- rougail.val1.variable3
|
||||||
|
- __.val1.variable3
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
@ -235,12 +316,12 @@ An example with parameters:
|
||||||
param1: value
|
param1: value
|
||||||
param2:
|
param2:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.unknown_variable
|
variable: _.unknown_variable
|
||||||
optional: true
|
optional: true
|
||||||
param3:
|
param3:
|
||||||
type: information
|
type: information
|
||||||
information: doc
|
information: doc
|
||||||
variable: rougail.my_calculated_variable
|
variable: _.my_calculated_variable
|
||||||
|
|
||||||
An example with a `suffix` type parameter:
|
An example with a `suffix` type parameter:
|
||||||
|
|
||||||
|
@ -257,7 +338,7 @@ An example with a `suffix` type parameter:
|
||||||
type: dynamic
|
type: dynamic
|
||||||
dynamic:
|
dynamic:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.varname
|
variable: _.varname
|
||||||
description: 'Describe '
|
description: 'Describe '
|
||||||
my_dyn_var:
|
my_dyn_var:
|
||||||
type: string
|
type: string
|
||||||
|
@ -311,7 +392,7 @@ Copy a variable in another:
|
||||||
multi: true
|
multi: true
|
||||||
default:
|
default:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.my_variable
|
variable: _.my_variable
|
||||||
|
|
||||||
Copy one variable to another if the source has no `property` problem:
|
Copy one variable to another if the source has no `property` problem:
|
||||||
|
|
||||||
|
@ -326,7 +407,7 @@ Copy one variable to another if the source has no `property` problem:
|
||||||
multi: true
|
multi: true
|
||||||
default:
|
default:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.my_variable
|
variable: _.my_variable
|
||||||
propertyerror: false
|
propertyerror: false
|
||||||
|
|
||||||
Copy two non-multiple variables into a multiple variable:
|
Copy two non-multiple variables into a multiple variable:
|
||||||
|
@ -343,9 +424,9 @@ Copy two non-multiple variables into a multiple variable:
|
||||||
multi: true
|
multi: true
|
||||||
default:
|
default:
|
||||||
- type: variable
|
- type: variable
|
||||||
variable: rougail.my_variable_1
|
variable: _.my_variable_1
|
||||||
- type: variable
|
- type: variable
|
||||||
variable: rougail.my_variable_2
|
variable: _.my_variable_2
|
||||||
|
|
||||||
A variable in a dynamic family can also be used in a calculation.
|
A variable in a dynamic family can also be used in a calculation.
|
||||||
|
|
||||||
|
@ -364,7 +445,7 @@ For example using the variable for a particular suffix:
|
||||||
type: dynamic
|
type: dynamic
|
||||||
dynamic:
|
dynamic:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.varname
|
variable: _.varname
|
||||||
description: 'Describe '
|
description: 'Describe '
|
||||||
my_dyn_var_:
|
my_dyn_var_:
|
||||||
type: string
|
type: string
|
||||||
|
@ -373,7 +454,7 @@ For example using the variable for a particular suffix:
|
||||||
all_dyn_var:
|
all_dyn_var:
|
||||||
default:
|
default:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.my_dyn_family_val1.my_dyn_var_val1
|
variable: _.my_dyn_family_val1.my_dyn_var_val1
|
||||||
|
|
||||||
In this case, we recover the value `val1`.
|
In this case, we recover the value `val1`.
|
||||||
|
|
||||||
|
@ -392,7 +473,7 @@ Second example using the variable for all suffixes:
|
||||||
type: dynamic
|
type: dynamic
|
||||||
dynamic:
|
dynamic:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.varname
|
variable: _.varname
|
||||||
description: 'Describe '
|
description: 'Describe '
|
||||||
my_dyn_var_:
|
my_dyn_var_:
|
||||||
type: string
|
type: string
|
||||||
|
@ -402,7 +483,7 @@ Second example using the variable for all suffixes:
|
||||||
multi: true
|
multi: true
|
||||||
default:
|
default:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.my_dyn_family_.my_dyn_var_
|
variable: _.my_dyn_family_.my_dyn_var_
|
||||||
|
|
||||||
In this case, we recover the `val1` and `val2` list.
|
In this case, we recover the `val1` and `val2` list.
|
||||||
|
|
||||||
|
@ -422,7 +503,7 @@ Calculation via a suffix
|
||||||
type: dynamic
|
type: dynamic
|
||||||
dynamic:
|
dynamic:
|
||||||
type: variable
|
type: variable
|
||||||
variable: rougail.varname
|
variable: _.varname
|
||||||
description: 'Describe '
|
description: 'Describe '
|
||||||
my_dyn_var_:
|
my_dyn_var_:
|
||||||
type: string
|
type: string
|
||||||
|
|
|
@ -42,7 +42,7 @@ from typing import (
|
||||||
Tuple,
|
Tuple,
|
||||||
)
|
)
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from re import findall
|
from re import findall, compile
|
||||||
|
|
||||||
from yaml import safe_load
|
from yaml import safe_load
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
|
@ -97,6 +97,8 @@ class Property:
|
||||||
|
|
||||||
|
|
||||||
class Paths:
|
class Paths:
|
||||||
|
_regexp_relative = compile(r"^_*\.(.*)$")
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._data: Dict[str, Union[Variable, Family]] = {}
|
self._data: Dict[str, Union[Variable, Family]] = {}
|
||||||
self._dynamics: List[str] = []
|
self._dynamics: List[str] = []
|
||||||
|
@ -110,6 +112,7 @@ class Paths:
|
||||||
path: str,
|
path: str,
|
||||||
data: Any,
|
data: Any,
|
||||||
is_dynamic: bool,
|
is_dynamic: bool,
|
||||||
|
*,
|
||||||
force: bool = False,
|
force: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
self._data[path] = data
|
self._data[path] = data
|
||||||
|
@ -119,24 +122,34 @@ class Paths:
|
||||||
def get_with_dynamic(
|
def get_with_dynamic(
|
||||||
self,
|
self,
|
||||||
path: str,
|
path: str,
|
||||||
|
suffix_path: str,
|
||||||
|
current_path: str,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
suffix = None
|
suffix = None
|
||||||
|
if self._regexp_relative.search(path):
|
||||||
|
relative, subpath = path.split(".", 1)
|
||||||
|
relative_len = len(relative)
|
||||||
|
path_len = current_path.count(".")
|
||||||
|
parent_path = current_path.rsplit(".", relative_len)[0]
|
||||||
|
path = parent_path + "." + subpath
|
||||||
|
else:
|
||||||
|
path = get_realpath(path, suffix_path)
|
||||||
dynamic_path = None
|
dynamic_path = None
|
||||||
dynamic_variable_path = None
|
dynamic_variable_path = None
|
||||||
if not path in self._data:
|
if not path in self._data:
|
||||||
for dynamic in self._dynamics:
|
for dynamic in self._dynamics:
|
||||||
if "{{ suffix }}" in dynamic:
|
if "{{ suffix }}" in dynamic:
|
||||||
regexp = "^" + dynamic.replace('{{ suffix }}', '(.*)') + '.'
|
regexp = "^" + dynamic.replace("{{ suffix }}", "(.*)") + "."
|
||||||
finded = findall(regexp, path)
|
finded = findall(regexp, path)
|
||||||
if len(finded) != 1:
|
if len(finded) != 1:
|
||||||
continue
|
continue
|
||||||
splitted_dynamic = dynamic.split('.')
|
splitted_dynamic = dynamic.split(".")
|
||||||
splitted_path = path.split('.')
|
splitted_path = path.split(".")
|
||||||
for idx, s in enumerate(splitted_dynamic):
|
for idx, s in enumerate(splitted_dynamic):
|
||||||
if '{{ suffix }}' in s:
|
if "{{ suffix }}" in s:
|
||||||
break
|
break
|
||||||
|
|
||||||
suffix_path = '.'.join(splitted_path[idx + 1:])
|
suffix_path = ".".join(splitted_path[idx + 1 :])
|
||||||
if suffix_path:
|
if suffix_path:
|
||||||
suffix_path = "." + suffix_path
|
suffix_path = "." + suffix_path
|
||||||
suffix = splitted_path[idx] + suffix_path
|
suffix = splitted_path[idx] + suffix_path
|
||||||
|
@ -478,6 +491,9 @@ class ParserVariable:
|
||||||
):
|
):
|
||||||
# it's a dict, so a new variables!
|
# it's a dict, so a new variables!
|
||||||
continue
|
continue
|
||||||
|
# FIXME should be remove with 1.0 format
|
||||||
|
if key == "variable" and obj.get("type") != "dynamic":
|
||||||
|
continue
|
||||||
if key in self.family_attrs:
|
if key in self.family_attrs:
|
||||||
yield key
|
yield key
|
||||||
|
|
||||||
|
|
|
@ -148,11 +148,12 @@ class Calculation(BaseModel):
|
||||||
for param_obj in self.params:
|
for param_obj in self.params:
|
||||||
param = param_obj.model_dump()
|
param = param_obj.model_dump()
|
||||||
if param.get("type") == "variable":
|
if param.get("type") == "variable":
|
||||||
variable_path = self.get_realpath(param["variable"])
|
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(
|
||||||
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(variable_path)
|
param["variable"], self.path_prefix, self.path
|
||||||
|
)
|
||||||
if not variable:
|
if not variable:
|
||||||
if not param.get("optional"):
|
if not param.get("optional"):
|
||||||
raise Exception(f"cannot find {variable_path}")
|
raise Exception(f"cannot find {param['variable']}")
|
||||||
continue
|
continue
|
||||||
if not isinstance(variable, objectspace.variable):
|
if not isinstance(variable, objectspace.variable):
|
||||||
raise Exception("pfff it's a family")
|
raise Exception("pfff it's a family")
|
||||||
|
@ -162,10 +163,15 @@ class Calculation(BaseModel):
|
||||||
param["dynamic"] = dynamic
|
param["dynamic"] = dynamic
|
||||||
if param.get("type") == "information":
|
if param.get("type") == "information":
|
||||||
if param["variable"]:
|
if param["variable"]:
|
||||||
variable_path = self.get_realpath(param["variable"])
|
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(
|
||||||
param["variable"] = objectspace.paths[variable_path]
|
param["variable"], self.path_prefix, self.path
|
||||||
if not param["variable"]:
|
)
|
||||||
|
# variable_path = self.get_realpath(param["variable"])
|
||||||
|
if not variable:
|
||||||
raise Exception("pffff")
|
raise Exception("pffff")
|
||||||
|
param["variable"] = variable
|
||||||
|
if suffix:
|
||||||
|
raise Exception("pff not dynamic with information")
|
||||||
else:
|
else:
|
||||||
del param["variable"]
|
del param["variable"]
|
||||||
params[param.pop("key")] = param
|
params[param.pop("key")] = param
|
||||||
|
@ -212,6 +218,7 @@ class JinjaCalculation(Calculation):
|
||||||
if params:
|
if params:
|
||||||
default["params"] |= params
|
default["params"] |= params
|
||||||
for sub_variable, suffix, true_path, dynamic in get_jinja_variable_to_param(
|
for sub_variable, suffix, true_path, dynamic in get_jinja_variable_to_param(
|
||||||
|
self.path,
|
||||||
self.jinja,
|
self.jinja,
|
||||||
objectspace,
|
objectspace,
|
||||||
variable.xmlfiles,
|
variable.xmlfiles,
|
||||||
|
@ -300,8 +307,9 @@ class VariableCalculation(Calculation):
|
||||||
self,
|
self,
|
||||||
objectspace,
|
objectspace,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
variable_path = self.get_realpath(self.variable)
|
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(
|
||||||
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(variable_path)
|
self.variable, self.path_prefix, self.path
|
||||||
|
)
|
||||||
if not variable:
|
if not variable:
|
||||||
raise VariableNotFoundError(f"Variable not found {variable_path}", variable_path)
|
raise VariableNotFoundError(f"Variable not found {variable_path}", variable_path)
|
||||||
if not isinstance(variable, objectspace.variable):
|
if not isinstance(variable, objectspace.variable):
|
||||||
|
@ -325,11 +333,7 @@ class VariableCalculation(Calculation):
|
||||||
raise Exception("only boolean!")
|
raise Exception("only boolean!")
|
||||||
params[None].insert(0, self.attribute_name)
|
params[None].insert(0, self.attribute_name)
|
||||||
if not self.inside_list and self.path in objectspace.multis:
|
if not self.inside_list and self.path in objectspace.multis:
|
||||||
if (
|
variable_path = self.get_realpath(self.variable)
|
||||||
not objectspace.paths.is_dynamic(variable_path)
|
|
||||||
and variable_path not in objectspace.multis
|
|
||||||
):
|
|
||||||
params["multi"] = True
|
|
||||||
params["allow_none"] = True
|
params["allow_none"] = True
|
||||||
if self.inside_list and variable.path in objectspace.multis:
|
if self.inside_list and variable.path in objectspace.multis:
|
||||||
raise Exception("pfff")
|
raise Exception("pfff")
|
||||||
|
|
|
@ -1,527 +0,0 @@
|
||||||
"""Manage path to find objects
|
|
||||||
|
|
||||||
Created by:
|
|
||||||
EOLE (http://eole.orion.education.fr)
|
|
||||||
Copyright (C) 2005-2018
|
|
||||||
|
|
||||||
Forked by:
|
|
||||||
Cadoles (http://www.cadoles.com)
|
|
||||||
Copyright (C) 2019-2021
|
|
||||||
|
|
||||||
Silique (https://www.silique.fr)
|
|
||||||
Copyright (C) 2022-2024
|
|
||||||
|
|
||||||
distribued with GPL-2 or later license
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
"""
|
|
||||||
from typing import List
|
|
||||||
from .i18n import _
|
|
||||||
from .error import DictConsistencyError
|
|
||||||
from .utils import normalize_family
|
|
||||||
|
|
||||||
|
|
||||||
class Path:
|
|
||||||
"""Helper class to handle the `path` attribute.
|
|
||||||
|
|
||||||
sample: path="creole.general.condition"
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
rougailconfig: "RougailConfig",
|
|
||||||
) -> None:
|
|
||||||
self.variables = {}
|
|
||||||
self.families = {}
|
|
||||||
# self.names = {}
|
|
||||||
self.full_paths_families = {}
|
|
||||||
self.full_paths_variables = {}
|
|
||||||
self.full_dyn_paths_families = {}
|
|
||||||
self.valid_enums = {}
|
|
||||||
self.variable_namespace = rougailconfig["variable_namespace"]
|
|
||||||
self.providers = {}
|
|
||||||
self.suppliers = {}
|
|
||||||
self.list_conditions = {}
|
|
||||||
self.suffix = rougailconfig["suffix"]
|
|
||||||
self.index = 0
|
|
||||||
|
|
||||||
def set_path_prefix(self, prefix: str) -> None:
|
|
||||||
self._path_prefix = prefix
|
|
||||||
if prefix:
|
|
||||||
if None in self.full_paths_families:
|
|
||||||
raise DictConsistencyError(
|
|
||||||
_(f'prefix "{prefix}" cannot be set if a prefix "None" exists'),
|
|
||||||
39,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
for old_prefix in self.full_paths_families:
|
|
||||||
if old_prefix != None:
|
|
||||||
raise DictConsistencyError(
|
|
||||||
_(f"no prefix cannot be set if a prefix exists"), 84, None
|
|
||||||
)
|
|
||||||
if prefix in self.full_paths_families:
|
|
||||||
raise DictConsistencyError(_(f'prefix "{prefix}" already exists'), 83, None)
|
|
||||||
self.full_paths_families[prefix] = {}
|
|
||||||
self.full_paths_variables[prefix] = {}
|
|
||||||
self.valid_enums[prefix] = {}
|
|
||||||
self.providers[prefix] = {}
|
|
||||||
self.suppliers[prefix] = {}
|
|
||||||
self.list_conditions[prefix] = {}
|
|
||||||
|
|
||||||
def has_path_prefix(self) -> bool:
|
|
||||||
return None not in self.full_paths_families
|
|
||||||
|
|
||||||
def get_path_prefixes(self) -> list:
|
|
||||||
return list(self.full_paths_families)
|
|
||||||
|
|
||||||
def get_path_prefix(self) -> str:
|
|
||||||
return self._path_prefix
|
|
||||||
|
|
||||||
# Family
|
|
||||||
def add_family(
|
|
||||||
self,
|
|
||||||
namespace: str,
|
|
||||||
subpath: str,
|
|
||||||
variableobj: str,
|
|
||||||
is_dynamic: str,
|
|
||||||
force_path_prefix: str = None,
|
|
||||||
) -> str: # pylint: disable=C0111
|
|
||||||
"""Add a new family"""
|
|
||||||
if force_path_prefix is None:
|
|
||||||
force_path_prefix = self._path_prefix
|
|
||||||
path = subpath + "." + variableobj.name
|
|
||||||
if namespace == self.variable_namespace:
|
|
||||||
if variableobj.name in self.full_paths_families[force_path_prefix]:
|
|
||||||
msg = _(f'Duplicate family name "{variableobj.name}"')
|
|
||||||
raise DictConsistencyError(msg, 55, variableobj.xmlfiles)
|
|
||||||
self.full_paths_families[force_path_prefix][variableobj.name] = path
|
|
||||||
if is_dynamic:
|
|
||||||
if subpath in self.full_dyn_paths_families:
|
|
||||||
dyn_subpath = self.full_dyn_paths_families[subpath]
|
|
||||||
else:
|
|
||||||
dyn_subpath = subpath
|
|
||||||
self.full_dyn_paths_families[
|
|
||||||
path
|
|
||||||
] = f"{dyn_subpath}.{variableobj.name}{{suffix}}"
|
|
||||||
if path in self.families:
|
|
||||||
msg = _(f'Duplicate family name "{path}"')
|
|
||||||
raise DictConsistencyError(msg, 37, variableobj.xmlfiles)
|
|
||||||
if path in self.variables:
|
|
||||||
msg = _(f'A variable and a family has the same path "{path}"')
|
|
||||||
raise DictConsistencyError(msg, 56, variableobj.xmlfiles)
|
|
||||||
self.families[path] = dict(
|
|
||||||
name=path,
|
|
||||||
namespace=namespace,
|
|
||||||
variableobj=variableobj,
|
|
||||||
)
|
|
||||||
self.set_name(variableobj, "optiondescription_")
|
|
||||||
variableobj.path = path
|
|
||||||
variableobj.path_prefix = force_path_prefix
|
|
||||||
|
|
||||||
def get_family(
|
|
||||||
self,
|
|
||||||
path: str,
|
|
||||||
current_namespace: str,
|
|
||||||
path_prefix: str,
|
|
||||||
allow_variable_namespace: bool = False,
|
|
||||||
) -> "Family": # pylint: disable=C0111
|
|
||||||
"""Get a family"""
|
|
||||||
if (
|
|
||||||
current_namespace == self.variable_namespace or allow_variable_namespace
|
|
||||||
) and path in self.full_paths_families[path_prefix]:
|
|
||||||
path = self.full_paths_families[path_prefix][path]
|
|
||||||
elif allow_variable_namespace and path_prefix:
|
|
||||||
path = f"{path_prefix}.{path}"
|
|
||||||
if path not in self.families:
|
|
||||||
raise DictConsistencyError(_(f'unknown option "{path}"'), 42, [])
|
|
||||||
dico = self.families[path]
|
|
||||||
if current_namespace != dico["namespace"] and (
|
|
||||||
not allow_variable_namespace or current_namespace != self.variable_namespace
|
|
||||||
):
|
|
||||||
msg = _(
|
|
||||||
f'A family located in the "{dico["namespace"]}" namespace '
|
|
||||||
f'shall not be used in the "{current_namespace}" namespace'
|
|
||||||
)
|
|
||||||
raise DictConsistencyError(msg, 38, [])
|
|
||||||
return dico["variableobj"]
|
|
||||||
|
|
||||||
def _get_dyn_path(
|
|
||||||
self,
|
|
||||||
subpath: str,
|
|
||||||
name: bool,
|
|
||||||
) -> str:
|
|
||||||
if subpath in self.full_dyn_paths_families:
|
|
||||||
subpath = self.full_dyn_paths_families[subpath]
|
|
||||||
path = f"{subpath}.{name}{{suffix}}"
|
|
||||||
else:
|
|
||||||
path = f"{subpath}.{name}"
|
|
||||||
return path
|
|
||||||
|
|
||||||
def set_provider(
|
|
||||||
self,
|
|
||||||
variableobj,
|
|
||||||
name,
|
|
||||||
family,
|
|
||||||
):
|
|
||||||
if not hasattr(variableobj, "provider"):
|
|
||||||
return
|
|
||||||
p_name = "provider:" + variableobj.provider
|
|
||||||
if "." in name:
|
|
||||||
msg = f'provider "{p_name}" not allowed in extra'
|
|
||||||
raise DictConsistencyError(msg, 82, variableobj.xmlfiles)
|
|
||||||
if p_name in self.providers[variableobj.path_prefix]:
|
|
||||||
msg = f'provider "{p_name}" declare multiple time'
|
|
||||||
raise DictConsistencyError(msg, 79, variableobj.xmlfiles)
|
|
||||||
self.providers[variableobj.path_prefix][p_name] = {
|
|
||||||
"path": self._get_dyn_path(
|
|
||||||
family,
|
|
||||||
name,
|
|
||||||
),
|
|
||||||
"option": variableobj,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_provider(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
path_prefix: str = None,
|
|
||||||
) -> "self.objectspace.variable":
|
|
||||||
return self.providers[path_prefix][name]["option"]
|
|
||||||
|
|
||||||
def get_providers_path(self, path_prefix=None):
|
|
||||||
if path_prefix:
|
|
||||||
return {
|
|
||||||
name: option["path"].split(".", 1)[-1]
|
|
||||||
for name, option in self.providers[path_prefix].items()
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
name: option["path"] for name, option in self.providers[path_prefix].items()
|
|
||||||
}
|
|
||||||
|
|
||||||
def set_supplier(
|
|
||||||
self,
|
|
||||||
variableobj,
|
|
||||||
name,
|
|
||||||
family,
|
|
||||||
):
|
|
||||||
if not hasattr(variableobj, "supplier"):
|
|
||||||
return
|
|
||||||
s_name = "supplier:" + variableobj.supplier
|
|
||||||
if "." in name:
|
|
||||||
msg = f'supplier "{s_name}" not allowed in extra'
|
|
||||||
raise DictConsistencyError(msg, 82, variableobj.xmlfiles)
|
|
||||||
if s_name in self.suppliers[variableobj.path_prefix]:
|
|
||||||
msg = f'supplier "{s_name}" declare multiple time'
|
|
||||||
raise DictConsistencyError(msg, 79, variableobj.xmlfiles)
|
|
||||||
self.suppliers[variableobj.path_prefix][s_name] = {
|
|
||||||
"path": self._get_dyn_path(family, name),
|
|
||||||
"option": variableobj,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_supplier(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
path_prefix: str = None,
|
|
||||||
) -> "self.objectspace.variable":
|
|
||||||
return self.suppliers[path_prefix][name]["option"]
|
|
||||||
|
|
||||||
def get_suppliers_path(self, path_prefix=None):
|
|
||||||
if path_prefix:
|
|
||||||
return {
|
|
||||||
name: option["path"].split(".", 1)[-1]
|
|
||||||
for name, option in self.suppliers[path_prefix].items()
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
name: option["path"] for name, option in self.suppliers[path_prefix].items()
|
|
||||||
}
|
|
||||||
|
|
||||||
# Variable
|
|
||||||
def add_variable(
|
|
||||||
self, # pylint: disable=R0913
|
|
||||||
namespace: str,
|
|
||||||
subpath: str,
|
|
||||||
variableobj: "self.objectspace.variable",
|
|
||||||
is_dynamic: bool = False,
|
|
||||||
is_leader: bool = False,
|
|
||||||
force_path_prefix: str = None,
|
|
||||||
) -> str: # pylint: disable=C0111
|
|
||||||
"""Add a new variable (with path)"""
|
|
||||||
if force_path_prefix is None:
|
|
||||||
force_path_prefix = self._path_prefix
|
|
||||||
path = subpath + "." + variableobj.name
|
|
||||||
if namespace == self.variable_namespace:
|
|
||||||
self.full_paths_variables[force_path_prefix][variableobj.name] = path
|
|
||||||
if path in self.families:
|
|
||||||
msg = _(f'A family and a variable has the same path "{path}"')
|
|
||||||
raise DictConsistencyError(msg, 57, variableobj.xmlfiles)
|
|
||||||
if is_leader:
|
|
||||||
leader = subpath
|
|
||||||
else:
|
|
||||||
leader = None
|
|
||||||
self.variables[path] = dict(
|
|
||||||
name=path,
|
|
||||||
family=subpath,
|
|
||||||
leader=leader,
|
|
||||||
is_dynamic=is_dynamic,
|
|
||||||
variableobj=variableobj,
|
|
||||||
)
|
|
||||||
variableobj.path = path
|
|
||||||
variableobj.path_prefix = force_path_prefix
|
|
||||||
self.set_name(variableobj, "option_")
|
|
||||||
|
|
||||||
def set_name(
|
|
||||||
self,
|
|
||||||
variableobj,
|
|
||||||
option_prefix,
|
|
||||||
):
|
|
||||||
self.index += 1
|
|
||||||
variableobj.reflector_name = f"{option_prefix}{self.index}{self.suffix}"
|
|
||||||
|
|
||||||
def get_variable(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
namespace: str,
|
|
||||||
xmlfiles: List[str] = [],
|
|
||||||
allow_variable_namespace: bool = False,
|
|
||||||
force_path_prefix: str = None,
|
|
||||||
add_path_prefix: bool = False,
|
|
||||||
) -> "Variable": # pylint: disable=C0111
|
|
||||||
"""Get variable object from a path"""
|
|
||||||
if force_path_prefix is None:
|
|
||||||
force_path_prefix = self._path_prefix
|
|
||||||
try:
|
|
||||||
variable, suffix = self._get_variable(
|
|
||||||
name,
|
|
||||||
namespace,
|
|
||||||
with_suffix=True,
|
|
||||||
xmlfiles=xmlfiles,
|
|
||||||
path_prefix=force_path_prefix,
|
|
||||||
add_path_prefix=add_path_prefix,
|
|
||||||
)
|
|
||||||
except DictConsistencyError as err:
|
|
||||||
if (
|
|
||||||
not allow_variable_namespace
|
|
||||||
or err.errno != 42
|
|
||||||
or namespace == self.variable_namespace
|
|
||||||
):
|
|
||||||
raise err from err
|
|
||||||
variable, suffix = self._get_variable(
|
|
||||||
name,
|
|
||||||
self.variable_namespace,
|
|
||||||
with_suffix=True,
|
|
||||||
xmlfiles=xmlfiles,
|
|
||||||
path_prefix=force_path_prefix,
|
|
||||||
)
|
|
||||||
if suffix:
|
|
||||||
raise DictConsistencyError(_(f"{name} is a dynamic variable"), 36, [])
|
|
||||||
return variable["variableobj"]
|
|
||||||
|
|
||||||
def get_variable_family_path(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
namespace: str,
|
|
||||||
xmlfiles: List[str] = False,
|
|
||||||
force_path_prefix: str = None,
|
|
||||||
) -> str: # pylint: disable=C0111
|
|
||||||
"""Get the full path of a family"""
|
|
||||||
if force_path_prefix is None:
|
|
||||||
force_path_prefix = self._path_prefix
|
|
||||||
return self._get_variable(
|
|
||||||
name,
|
|
||||||
namespace,
|
|
||||||
xmlfiles=xmlfiles,
|
|
||||||
path_prefix=force_path_prefix,
|
|
||||||
)["family"]
|
|
||||||
|
|
||||||
def get_variable_with_suffix(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
current_namespace: str,
|
|
||||||
xmlfiles: List[str],
|
|
||||||
path_prefix: str,
|
|
||||||
) -> str: # pylint: disable=C0111
|
|
||||||
"""get full path of a variable"""
|
|
||||||
try:
|
|
||||||
dico, suffix = self._get_variable(
|
|
||||||
name,
|
|
||||||
current_namespace,
|
|
||||||
with_suffix=True,
|
|
||||||
xmlfiles=xmlfiles,
|
|
||||||
path_prefix=path_prefix,
|
|
||||||
add_path_prefix=True,
|
|
||||||
)
|
|
||||||
except DictConsistencyError as err:
|
|
||||||
if err.errno != 42 or current_namespace == self.variable_namespace:
|
|
||||||
raise err from err
|
|
||||||
dico, suffix = self._get_variable(
|
|
||||||
name,
|
|
||||||
self.variable_namespace,
|
|
||||||
with_suffix=True,
|
|
||||||
xmlfiles=xmlfiles,
|
|
||||||
path_prefix=path_prefix,
|
|
||||||
add_path_prefix=True,
|
|
||||||
)
|
|
||||||
namespace = dico["variableobj"].namespace
|
|
||||||
if (
|
|
||||||
namespace not in [self.variable_namespace, "services"]
|
|
||||||
and current_namespace != "services"
|
|
||||||
and current_namespace != namespace
|
|
||||||
):
|
|
||||||
msg = _(
|
|
||||||
f'A variable located in the "{namespace}" namespace shall not be used '
|
|
||||||
f'in the "{current_namespace}" namespace'
|
|
||||||
)
|
|
||||||
raise DictConsistencyError(msg, 41, xmlfiles)
|
|
||||||
return dico["variableobj"], suffix
|
|
||||||
|
|
||||||
def path_is_defined(
|
|
||||||
self,
|
|
||||||
path: str,
|
|
||||||
namespace: str,
|
|
||||||
force_path_prefix: str = None,
|
|
||||||
) -> str: # pylint: disable=C0111
|
|
||||||
"""The path is a valid path"""
|
|
||||||
if namespace == self.variable_namespace:
|
|
||||||
if force_path_prefix is None:
|
|
||||||
force_path_prefix = self._path_prefix
|
|
||||||
return path in self.full_paths_variables[force_path_prefix]
|
|
||||||
return path in self.variables
|
|
||||||
|
|
||||||
def get_path(
|
|
||||||
self,
|
|
||||||
path: str,
|
|
||||||
namespace: str,
|
|
||||||
) -> str:
|
|
||||||
if namespace == self.variable_namespace:
|
|
||||||
if path not in self.full_paths_variables[self._path_prefix]:
|
|
||||||
return None
|
|
||||||
path = self.full_paths_variables[self._path_prefix][path]
|
|
||||||
else:
|
|
||||||
path = f"{self._path_prefix}.{path}"
|
|
||||||
return path
|
|
||||||
|
|
||||||
def is_dynamic(self, variableobj) -> bool:
|
|
||||||
"""This variable is in dynamic family"""
|
|
||||||
return self._get_variable(
|
|
||||||
variableobj.path,
|
|
||||||
variableobj.namespace,
|
|
||||||
path_prefix=variableobj.path_prefix,
|
|
||||||
)["is_dynamic"]
|
|
||||||
|
|
||||||
def is_leader(self, variableobj): # pylint: disable=C0111
|
|
||||||
"""Is the variable is a leader"""
|
|
||||||
path = variableobj.path
|
|
||||||
variable = self._get_variable(
|
|
||||||
path,
|
|
||||||
variableobj.namespace,
|
|
||||||
path_prefix=variableobj.path_prefix,
|
|
||||||
)
|
|
||||||
if not variable["leader"]:
|
|
||||||
return False
|
|
||||||
leadership = self.get_family(
|
|
||||||
variable["leader"],
|
|
||||||
variableobj.namespace,
|
|
||||||
path_prefix=variableobj.path_prefix,
|
|
||||||
)
|
|
||||||
return next(iter(leadership.variable.values())).path == path
|
|
||||||
|
|
||||||
def is_follower(self, variableobj) -> bool:
|
|
||||||
"""Is the variable is a follower"""
|
|
||||||
variable = self._get_variable(
|
|
||||||
variableobj.path,
|
|
||||||
variableobj.namespace,
|
|
||||||
path_prefix=variableobj.path_prefix,
|
|
||||||
)
|
|
||||||
if not variable["leader"]:
|
|
||||||
return False
|
|
||||||
leadership = self.get_family(
|
|
||||||
variable["leader"],
|
|
||||||
variableobj.namespace,
|
|
||||||
path_prefix=variableobj.path_prefix,
|
|
||||||
)
|
|
||||||
return next(iter(leadership.variable.values())).path != variableobj.path
|
|
||||||
|
|
||||||
def get_leader(self, variableobj) -> str:
|
|
||||||
variable = self._get_variable(
|
|
||||||
variableobj.path,
|
|
||||||
variableobj.namespace,
|
|
||||||
path_prefix=variableobj.path_prefix,
|
|
||||||
)
|
|
||||||
if not variable["leader"]:
|
|
||||||
raise Exception(f"cannot find leader for {variableobj.path}")
|
|
||||||
leadership = self.get_family(
|
|
||||||
variable["leader"],
|
|
||||||
variableobj.namespace,
|
|
||||||
path_prefix=variableobj.path_prefix,
|
|
||||||
)
|
|
||||||
return next(iter(leadership.variable.values()))
|
|
||||||
|
|
||||||
def _get_variable(
|
|
||||||
self,
|
|
||||||
path: str,
|
|
||||||
namespace: str,
|
|
||||||
with_suffix: bool = False,
|
|
||||||
xmlfiles: List[str] = [],
|
|
||||||
path_prefix: str = None,
|
|
||||||
add_path_prefix: bool = False,
|
|
||||||
) -> str:
|
|
||||||
if namespace == self.variable_namespace:
|
|
||||||
if path in self.full_paths_variables[path_prefix]:
|
|
||||||
path = self.full_paths_variables[path_prefix][path]
|
|
||||||
else:
|
|
||||||
if with_suffix:
|
|
||||||
for var_name, full_path in self.full_paths_variables[
|
|
||||||
path_prefix
|
|
||||||
].items():
|
|
||||||
if not path.startswith(var_name):
|
|
||||||
continue
|
|
||||||
variable = self._get_variable(
|
|
||||||
full_path, namespace, path_prefix=path_prefix
|
|
||||||
)
|
|
||||||
if not variable["is_dynamic"]:
|
|
||||||
continue
|
|
||||||
return variable, path[len(var_name) :]
|
|
||||||
if path_prefix and add_path_prefix:
|
|
||||||
path = f"{path_prefix}.{path}"
|
|
||||||
elif path_prefix and add_path_prefix:
|
|
||||||
path = f"{path_prefix}.{path}"
|
|
||||||
# FIXME with_suffix and variable in extra?
|
|
||||||
if path not in self.variables:
|
|
||||||
raise DictConsistencyError(_(f'unknown option "{path}"'), 42, xmlfiles)
|
|
||||||
if with_suffix:
|
|
||||||
return self.variables[path], None
|
|
||||||
return self.variables[path]
|
|
||||||
|
|
||||||
def set_valid_enums(
|
|
||||||
self,
|
|
||||||
path,
|
|
||||||
values,
|
|
||||||
path_prefix,
|
|
||||||
):
|
|
||||||
self.valid_enums[path_prefix][path] = values
|
|
||||||
|
|
||||||
def has_valid_enums(
|
|
||||||
self,
|
|
||||||
path: str,
|
|
||||||
path_prefix: str,
|
|
||||||
) -> bool:
|
|
||||||
return path in self.valid_enums[path_prefix]
|
|
||||||
|
|
||||||
def get_valid_enums(
|
|
||||||
self,
|
|
||||||
path: str,
|
|
||||||
path_prefix: str,
|
|
||||||
):
|
|
||||||
return self.valid_enums[path_prefix][path]
|
|
|
@ -87,6 +87,7 @@ def get_realpath(
|
||||||
|
|
||||||
|
|
||||||
def get_jinja_variable_to_param(
|
def get_jinja_variable_to_param(
|
||||||
|
current_path: str,
|
||||||
jinja_text,
|
jinja_text,
|
||||||
objectspace,
|
objectspace,
|
||||||
xmlfiles,
|
xmlfiles,
|
||||||
|
@ -113,7 +114,9 @@ def get_jinja_variable_to_param(
|
||||||
variables.sort()
|
variables.sort()
|
||||||
for variable_path in variables:
|
for variable_path in variables:
|
||||||
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(
|
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(
|
||||||
get_realpath(variable_path, path_prefix)
|
variable_path,
|
||||||
|
path_prefix,
|
||||||
|
current_path,
|
||||||
)
|
)
|
||||||
if variable and variable.path in objectspace.variables:
|
if variable and variable.path in objectspace.variables:
|
||||||
yield variable, suffix, variable_path, dynamic
|
yield variable, suffix, variable_path, dynamic
|
||||||
|
|
0
tests/dictionaries/10check_variable_relative/__init__.py
Normal file
0
tests/dictionaries/10check_variable_relative/__init__.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
var:
|
||||||
|
type: number
|
||||||
|
validators:
|
||||||
|
- type: jinja
|
||||||
|
jinja: |
|
||||||
|
{% if _.var > 10 %}
|
||||||
|
to high
|
||||||
|
{% endif %}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": null
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.general.var"]
|
|
@ -0,0 +1,73 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
dict_env['validators_rougail.general.var'] = "{% if _.var > 10 %}\nto high\n{% endif %}\n"
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_3 = IntOption(name="var", doc="var", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_rougail.general.var"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.var': ParamSelfOption(whole=False)}))], properties=frozenset({"basic", "mandatory"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"basic"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,79 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
dict_env['validators_1.rougail.general.var'] = "{% if _.var > 10 %}\nto high\n{% endif %}\n"
|
||||||
|
dict_env['validators_2.rougail.general.var'] = "{% if _.var > 10 %}\nto high\n{% endif %}\n"
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = IntOption(name="var", doc="var", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_1.rougail.general.var"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.var': ParamSelfOption(whole=False)}))], properties=frozenset({"basic", "mandatory"}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"basic"}))
|
||||||
|
option_8 = IntOption(name="var", doc="var", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_2.rougail.general.var"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.var': ParamSelfOption(whole=False)}))], properties=frozenset({"basic", "mandatory"}))
|
||||||
|
optiondescription_7 = OptionDescription(name="general", doc="general", children=[option_8], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_6 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_7], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_5 = OptionDescription(name="2", doc="2", children=[optiondescription_6], properties=frozenset({"basic"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_5])
|
|
@ -0,0 +1,8 @@
|
||||||
|
version: '1.0'
|
||||||
|
condition:
|
||||||
|
type: boolean
|
||||||
|
variable:
|
||||||
|
disabled:
|
||||||
|
type: variable
|
||||||
|
variable: _.condition
|
||||||
|
mandatory: false
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"rougail.condition": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"rougail.condition": true
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"rougail.condition": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1,72 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_2 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_3 = StrOption(name="variable", doc="variable", properties=frozenset({"standard", Calculation(func['variable_to_property'], Params((ParamValue("disabled"), ParamOption(option_2))), help_function=func['variable_to_property'])}))
|
||||||
|
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,77 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_3 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_4 = StrOption(name="variable", doc="variable", properties=frozenset({"standard", Calculation(func['variable_to_property'], Params((ParamValue("disabled"), ParamOption(option_3))), help_function=func['variable_to_property'])}))
|
||||||
|
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 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_8 = StrOption(name="variable", doc="variable", properties=frozenset({"standard", Calculation(func['variable_to_property'], Params((ParamValue("disabled"), ParamOption(option_7))), help_function=func['variable_to_property'])}))
|
||||||
|
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])
|
|
@ -1,3 +1,4 @@
|
||||||
|
---
|
||||||
version: '1.0'
|
version: '1.0'
|
||||||
general:
|
general:
|
||||||
mode_conteneur_actif:
|
mode_conteneur_actif:
|
||||||
|
@ -7,19 +8,12 @@ general:
|
||||||
default:
|
default:
|
||||||
type: jinja
|
type: jinja
|
||||||
jinja: '{% if __mode_conteneur_actif4 is defined %}
|
jinja: '{% if __mode_conteneur_actif4 is defined %}
|
||||||
|
|
||||||
{{ __mode_conteneur_actif4 }}
|
{{ __mode_conteneur_actif4 }}
|
||||||
|
|
||||||
{% elif __mode_conteneur_actif3 is defined %}
|
{% elif __mode_conteneur_actif3 is defined %}
|
||||||
|
|
||||||
{{ __mode_conteneur_actif3 }}
|
{{ __mode_conteneur_actif3 }}
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
{{ rougail.general.mode_conteneur_actif1 }}
|
{{ rougail.general.mode_conteneur_actif1 }}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
'
|
'
|
||||||
params:
|
params:
|
||||||
__mode_conteneur_actif4:
|
__mode_conteneur_actif4:
|
||||||
|
|
|
@ -63,7 +63,7 @@ func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
func['variable_to_property'] = variable_to_property
|
func['variable_to_property'] = variable_to_property
|
||||||
func['valid_with_jinja'] = valid_with_jinja
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
dict_env = {}
|
dict_env = {}
|
||||||
dict_env['default_rougail.general.mode_conteneur_actif'] = "{% if __mode_conteneur_actif4 is defined %}\n{{ __mode_conteneur_actif4 }}\n{% elif __mode_conteneur_actif3 is defined %}\n{{ __mode_conteneur_actif3 }}\n{% else %}\n{{ rougail.general.mode_conteneur_actif1 }}\n{% endif %}\n"
|
dict_env['default_rougail.general.mode_conteneur_actif'] = "{% if __mode_conteneur_actif4 is defined %} {{ __mode_conteneur_actif4 }} {% elif __mode_conteneur_actif3 is defined %} {{ __mode_conteneur_actif3 }} {% else %} {{ rougail.general.mode_conteneur_actif1 }} {% endif %} "
|
||||||
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
ENV.filters = func
|
ENV.filters = func
|
||||||
ENV.compile_templates('jinja_caches', zip=None)
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
|
|
@ -63,8 +63,8 @@ func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
func['variable_to_property'] = variable_to_property
|
func['variable_to_property'] = variable_to_property
|
||||||
func['valid_with_jinja'] = valid_with_jinja
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
dict_env = {}
|
dict_env = {}
|
||||||
dict_env['default_1.rougail.general.mode_conteneur_actif'] = "{% if __mode_conteneur_actif4 is defined %}\n{{ __mode_conteneur_actif4 }}\n{% elif __mode_conteneur_actif3 is defined %}\n{{ __mode_conteneur_actif3 }}\n{% else %}\n{{ rougail.general.mode_conteneur_actif1 }}\n{% endif %}\n"
|
dict_env['default_1.rougail.general.mode_conteneur_actif'] = "{% if __mode_conteneur_actif4 is defined %} {{ __mode_conteneur_actif4 }} {% elif __mode_conteneur_actif3 is defined %} {{ __mode_conteneur_actif3 }} {% else %} {{ rougail.general.mode_conteneur_actif1 }} {% endif %} "
|
||||||
dict_env['default_2.rougail.general.mode_conteneur_actif'] = "{% if __mode_conteneur_actif4 is defined %}\n{{ __mode_conteneur_actif4 }}\n{% elif __mode_conteneur_actif3 is defined %}\n{{ __mode_conteneur_actif3 }}\n{% else %}\n{{ rougail.general.mode_conteneur_actif1 }}\n{% endif %}\n"
|
dict_env['default_2.rougail.general.mode_conteneur_actif'] = "{% if __mode_conteneur_actif4 is defined %} {{ __mode_conteneur_actif4 }} {% elif __mode_conteneur_actif3 is defined %} {{ __mode_conteneur_actif3 }} {% else %} {{ rougail.general.mode_conteneur_actif1 }} {% endif %} "
|
||||||
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
ENV.filters = func
|
ENV.filters = func
|
||||||
ENV.compile_templates('jinja_caches', zip=None)
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
condition:
|
||||||
|
type: boolean
|
||||||
|
default: true
|
||||||
|
mode_conteneur_actif:
|
||||||
|
mandatory:
|
||||||
|
type: jinja
|
||||||
|
jinja: |
|
||||||
|
{% if _.condition == "yes" %}
|
||||||
|
condition is yes
|
||||||
|
{% endif %}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.condition": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"rougail.general.mode_conteneur_actif": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.general.condition": true,
|
||||||
|
"rougail.general.mode_conteneur_actif": null
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.condition": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"rougail.general.mode_conteneur_actif": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1,74 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
dict_env['mandatory_rougail.general.mode_conteneur_actif'] = "{% if _.condition == \"yes\" %}\ncondition is yes\n{% endif %}\n"
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_3 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_4 = StrOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", properties=frozenset({"standard", Calculation(func['jinja_to_property'], Params((ParamValue("mandatory")), kwargs={'__internal_jinja': ParamValue("mandatory_rougail.general.mode_conteneur_actif"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.condition': ParamOption(option_3)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,81 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
dict_env['mandatory_1.rougail.general.mode_conteneur_actif'] = "{% if _.condition == \"yes\" %}\ncondition is yes\n{% endif %}\n"
|
||||||
|
dict_env['mandatory_2.rougail.general.mode_conteneur_actif'] = "{% if _.condition == \"yes\" %}\ncondition is yes\n{% endif %}\n"
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_5 = StrOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", properties=frozenset({"standard", Calculation(func['jinja_to_property'], Params((ParamValue("mandatory")), kwargs={'__internal_jinja': ParamValue("mandatory_1.rougail.general.mode_conteneur_actif"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.condition': ParamOption(option_4)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4, option_5], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_9 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_10 = StrOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", properties=frozenset({"standard", Calculation(func['jinja_to_property'], Params((ParamValue("mandatory")), kwargs={'__internal_jinja': ParamValue("mandatory_2.rougail.general.mode_conteneur_actif"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.condition': ParamOption(option_9)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_8 = OptionDescription(name="general", doc="general", children=[option_9, option_10], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_7 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_8], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_6 = OptionDescription(name="2", doc="2", children=[optiondescription_7], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_6])
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
condition:
|
||||||
|
type: boolean
|
||||||
|
default: true
|
||||||
|
mode_conteneur_actif:
|
||||||
|
mandatory:
|
||||||
|
type: variable
|
||||||
|
variable: _.condition
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.condition": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"rougail.general.mode_conteneur_actif": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.general.condition": true,
|
||||||
|
"rougail.general.mode_conteneur_actif": null
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.condition": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
"rougail.general.mode_conteneur_actif": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.general.mode_conteneur_actif"]
|
|
@ -0,0 +1,73 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_3 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_4 = StrOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", properties=frozenset({"standard", Calculation(func['variable_to_property'], Params((ParamValue("mandatory"), ParamOption(option_3))), help_function=func['variable_to_property'])}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,79 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_5 = StrOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", properties=frozenset({"standard", Calculation(func['variable_to_property'], Params((ParamValue("mandatory"), ParamOption(option_4))), help_function=func['variable_to_property'])}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4, option_5], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_9 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_10 = StrOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", properties=frozenset({"standard", Calculation(func['variable_to_property'], Params((ParamValue("mandatory"), ParamOption(option_9))), help_function=func['variable_to_property'])}))
|
||||||
|
optiondescription_8 = OptionDescription(name="general", doc="general", children=[option_9, option_10], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_7 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_8], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_6 = OptionDescription(name="2", doc="2", children=[optiondescription_7], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_6])
|
0
tests/dictionaries/10load_param_relative/__init__.py
Normal file
0
tests/dictionaries/10load_param_relative/__init__.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
variable:
|
||||||
|
relative:
|
||||||
|
disabled:
|
||||||
|
type: jinja
|
||||||
|
params:
|
||||||
|
variable:
|
||||||
|
type: variable
|
||||||
|
variable: _.variable
|
||||||
|
optional: true
|
||||||
|
jinja: |
|
||||||
|
{% if variable is not defined %}
|
||||||
|
variable is undefined
|
||||||
|
{% elif variable == "no" %}
|
||||||
|
variable is no
|
||||||
|
{% endif %}
|
10
tests/dictionaries/10load_param_relative/makedict/after.json
Normal file
10
tests/dictionaries/10load_param_relative/makedict/after.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.variable": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"rougail.general.relative": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.general.variable": null,
|
||||||
|
"rougail.general.relative": null
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.variable": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"rougail.general.relative": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.general.variable", "rougail.general.relative"]
|
74
tests/dictionaries/10load_param_relative/tiramisu/base.py
Normal file
74
tests/dictionaries/10load_param_relative/tiramisu/base.py
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
dict_env['disabled_rougail.general.relative'] = "{% if variable is not defined %}\nvariable is undefined\n{% elif variable == \"no\" %}\nvariable is no\n{% endif %}\n"
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_3 = StrOption(name="variable", doc="variable", properties=frozenset({"basic", "mandatory"}))
|
||||||
|
option_4 = StrOption(name="relative", doc="relative", properties=frozenset({"basic", "mandatory", Calculation(func['jinja_to_property'], Params((ParamValue("disabled")), kwargs={'__internal_jinja': ParamValue("disabled_rougail.general.relative"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'variable': ParamOption(option_3)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"basic"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
81
tests/dictionaries/10load_param_relative/tiramisu/multi.py
Normal file
81
tests/dictionaries/10load_param_relative/tiramisu/multi.py
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
dict_env['disabled_1.rougail.general.relative'] = "{% if variable is not defined %}\nvariable is undefined\n{% elif variable == \"no\" %}\nvariable is no\n{% endif %}\n"
|
||||||
|
dict_env['disabled_2.rougail.general.relative'] = "{% if variable is not defined %}\nvariable is undefined\n{% elif variable == \"no\" %}\nvariable is no\n{% endif %}\n"
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = StrOption(name="variable", doc="variable", properties=frozenset({"basic", "mandatory"}))
|
||||||
|
option_5 = StrOption(name="relative", doc="relative", properties=frozenset({"basic", "mandatory", Calculation(func['jinja_to_property'], Params((ParamValue("disabled")), kwargs={'__internal_jinja': ParamValue("disabled_1.rougail.general.relative"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'variable': ParamOption(option_4)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4, option_5], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"basic"}))
|
||||||
|
option_9 = StrOption(name="variable", doc="variable", properties=frozenset({"basic", "mandatory"}))
|
||||||
|
option_10 = StrOption(name="relative", doc="relative", properties=frozenset({"basic", "mandatory", Calculation(func['jinja_to_property'], Params((ParamValue("disabled")), kwargs={'__internal_jinja': ParamValue("disabled_2.rougail.general.relative"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'variable': ParamOption(option_9)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_8 = OptionDescription(name="general", doc="general", children=[option_9, option_10], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_7 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_8], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_6 = OptionDescription(name="2", doc="2", children=[optiondescription_7], properties=frozenset({"basic"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_6])
|
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
relative:
|
||||||
|
disabled:
|
||||||
|
type: jinja
|
||||||
|
params:
|
||||||
|
variable:
|
||||||
|
type: variable
|
||||||
|
variable: _.variable
|
||||||
|
optional: true
|
||||||
|
jinja: |
|
||||||
|
{% if variable is not defined %}
|
||||||
|
variable is undefined
|
||||||
|
{% elif variable == "no" %}
|
||||||
|
variable is no
|
||||||
|
{% endif %}
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1,73 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
dict_env['disabled_rougail.general.relative'] = "{% if variable is not defined %}\nvariable is undefined\n{% elif variable == \"no\" %}\nvariable is no\n{% endif %}\n"
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_3 = StrOption(name="relative", doc="relative", properties=frozenset({"basic", "mandatory", Calculation(func['jinja_to_property'], Params((ParamValue("disabled")), kwargs={'__internal_jinja': ParamValue("disabled_rougail.general.relative"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"basic"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,79 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
dict_env['disabled_1.rougail.general.relative'] = "{% if variable is not defined %}\nvariable is undefined\n{% elif variable == \"no\" %}\nvariable is no\n{% endif %}\n"
|
||||||
|
dict_env['disabled_2.rougail.general.relative'] = "{% if variable is not defined %}\nvariable is undefined\n{% elif variable == \"no\" %}\nvariable is no\n{% endif %}\n"
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = StrOption(name="relative", doc="relative", properties=frozenset({"basic", "mandatory", Calculation(func['jinja_to_property'], Params((ParamValue("disabled")), kwargs={'__internal_jinja': ParamValue("disabled_1.rougail.general.relative"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"basic"}))
|
||||||
|
option_8 = StrOption(name="relative", doc="relative", properties=frozenset({"basic", "mandatory", Calculation(func['jinja_to_property'], Params((ParamValue("disabled")), kwargs={'__internal_jinja': ParamValue("disabled_2.rougail.general.relative"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False)}), help_function=func['jinja_to_property_help'])}))
|
||||||
|
optiondescription_7 = OptionDescription(name="general", doc="general", children=[option_8], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_6 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_7], properties=frozenset({"basic"}))
|
||||||
|
optiondescription_5 = OptionDescription(name="2", doc="2", children=[optiondescription_6], properties=frozenset({"basic"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_5])
|
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
mode_conteneur_actif:
|
||||||
|
type: choice
|
||||||
|
default: a
|
||||||
|
choices:
|
||||||
|
type: variable
|
||||||
|
variable: _.var
|
||||||
|
var:
|
||||||
|
multi: true
|
||||||
|
default:
|
||||||
|
- a
|
||||||
|
- b
|
||||||
|
- c
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"rougail.general.mode_conteneur_actif": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": [
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
"c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"rougail.general.mode_conteneur_actif": "a",
|
||||||
|
"rougail.general.var": [
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
"c"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"rougail.general.mode_conteneur_actif": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": [
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
"c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1,73 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = StrOption(name="var", doc="var", multi=True, default=["a", "b", "c"], default_multi="a", properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||||
|
option_3 = ChoiceOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", values=Calculation(func['calc_value'], Params((ParamOption(option_4)))), default="a", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,79 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_5 = StrOption(name="var", doc="var", multi=True, default=["a", "b", "c"], default_multi="a", properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||||
|
option_4 = ChoiceOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", values=Calculation(func['calc_value'], Params((ParamOption(option_5)))), default="a", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4, option_5], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_10 = StrOption(name="var", doc="var", multi=True, default=["a", "b", "c"], default_multi="a", properties=frozenset({"mandatory", "notempty", "standard"}))
|
||||||
|
option_9 = ChoiceOption(name="mode_conteneur_actif", doc="mode_conteneur_actif", values=Calculation(func['calc_value'], Params((ParamOption(option_10)))), default="a", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
optiondescription_8 = OptionDescription(name="general", doc="general", children=[option_9, option_10], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_7 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_8], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_6 = OptionDescription(name="2", doc="2", children=[optiondescription_7], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_6])
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
var:
|
||||||
|
hidden: true
|
||||||
|
default:
|
||||||
|
type: variable
|
||||||
|
variable: _.var2
|
||||||
|
var2:
|
||||||
|
default: "no"
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
"rougail.general.var2": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": "no",
|
||||||
|
"rougail.general.var2": "no"
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
"rougail.general.var2": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1,73 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = StrOption(name="var2", doc="var2", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_3 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_4)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,79 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_5 = StrOption(name="var2", doc="var2", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_4 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_5)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4, option_5], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_10 = StrOption(name="var2", doc="var2", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_9 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_10)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_8 = OptionDescription(name="general", doc="general", children=[option_9, option_10], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_7 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_8], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_6 = OptionDescription(name="2", doc="2", children=[optiondescription_7], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_6])
|
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
var:
|
||||||
|
hidden: true
|
||||||
|
multi: true
|
||||||
|
default:
|
||||||
|
- type: variable
|
||||||
|
variable: _.var2
|
||||||
|
- type: variable
|
||||||
|
variable: _.var3
|
||||||
|
var2:
|
||||||
|
default: "no"
|
||||||
|
var3:
|
||||||
|
default: "yes"
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": [
|
||||||
|
"no",
|
||||||
|
"yes"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"rougail.general.var2": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
"rougail.general.var3": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "yes"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": [
|
||||||
|
"no",
|
||||||
|
"yes"
|
||||||
|
],
|
||||||
|
"rougail.general.var2": "no",
|
||||||
|
"rougail.general.var3": "yes"
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": [
|
||||||
|
"no",
|
||||||
|
"yes"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"rougail.general.var2": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
"rougail.general.var3": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "yes"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1,74 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = StrOption(name="var2", doc="var2", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_5 = StrOption(name="var3", doc="var3", default="yes", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_3 = StrOption(name="var", doc="var", multi=True, default=[Calculation(func['calc_value'], Params((ParamOption(option_4)))), Calculation(func['calc_value'], Params((ParamOption(option_5))))], default_multi=Calculation(func['calc_value'], Params((ParamOption(option_4)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "notempty", "standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4, option_5], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,81 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_5 = StrOption(name="var2", doc="var2", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_6 = StrOption(name="var3", doc="var3", default="yes", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_4 = StrOption(name="var", doc="var", multi=True, default=[Calculation(func['calc_value'], Params((ParamOption(option_5)))), Calculation(func['calc_value'], Params((ParamOption(option_6))))], default_multi=Calculation(func['calc_value'], Params((ParamOption(option_5)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "notempty", "standard"}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4, option_5, option_6], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_11 = StrOption(name="var2", doc="var2", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_12 = StrOption(name="var3", doc="var3", default="yes", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_10 = StrOption(name="var", doc="var", multi=True, default=[Calculation(func['calc_value'], Params((ParamOption(option_11)))), Calculation(func['calc_value'], Params((ParamOption(option_12))))], default_multi=Calculation(func['calc_value'], Params((ParamOption(option_11)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "notempty", "standard"}))
|
||||||
|
optiondescription_9 = OptionDescription(name="general", doc="general", children=[option_10, option_11, option_12], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_8 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_9], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_7 = OptionDescription(name="2", doc="2", children=[optiondescription_8], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_7])
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
var:
|
||||||
|
default: "no"
|
||||||
|
fam1:
|
||||||
|
var:
|
||||||
|
hidden: true
|
||||||
|
default:
|
||||||
|
type: variable
|
||||||
|
variable: __.var
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
"rougail.general.fam1.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": "no",
|
||||||
|
"rougail.general.fam1.var": "no"
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
"rougail.general.fam1.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1,74 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_3 = StrOption(name="var", doc="var", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_5 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_3)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_4 = OptionDescription(name="fam1", doc="fam1", children=[option_5], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, optiondescription_4], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,81 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = StrOption(name="var", doc="var", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_6 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_4)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_5 = OptionDescription(name="fam1", doc="fam1", children=[option_6], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[option_4, optiondescription_5], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_10 = StrOption(name="var", doc="var", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
option_12 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_10)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_11 = OptionDescription(name="fam1", doc="fam1", children=[option_12], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_9 = OptionDescription(name="general", doc="general", children=[option_10, optiondescription_11], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_8 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_9], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_7 = OptionDescription(name="2", doc="2", children=[optiondescription_8], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_7])
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
fam2:
|
||||||
|
var:
|
||||||
|
default: "no"
|
||||||
|
fam1:
|
||||||
|
var:
|
||||||
|
hidden: true
|
||||||
|
default:
|
||||||
|
type: variable
|
||||||
|
variable: __.fam2.var
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.fam2.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
"rougail.general.fam1.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.general.fam2.var": "no",
|
||||||
|
"rougail.general.fam1.var": "no"
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.fam2.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
},
|
||||||
|
"rougail.general.fam1.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "no"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1,75 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_4 = StrOption(name="var", doc="var", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
optiondescription_3 = OptionDescription(name="fam2", doc="fam2", children=[option_4], properties=frozenset({"standard"}))
|
||||||
|
option_6 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_4)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_5 = OptionDescription(name="fam1", doc="fam1", children=[option_6], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="general", doc="general", children=[optiondescription_3, optiondescription_5], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
|
@ -0,0 +1,83 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
|
||||||
|
global func
|
||||||
|
func = {'calc_value': calc_value}
|
||||||
|
|
||||||
|
def _load_functions(path):
|
||||||
|
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
|
||||||
|
loader = _SourceFileLoader('func', path)
|
||||||
|
spec = _spec_from_loader(loader.name, loader)
|
||||||
|
func_ = _module_from_spec(spec)
|
||||||
|
loader.exec_module(func_)
|
||||||
|
for function in dir(func_):
|
||||||
|
if function.startswith('_'):
|
||||||
|
continue
|
||||||
|
func[function] = getattr(func_, function)
|
||||||
|
_load_functions('tests/dictionaries/../eosfunc/test.py')
|
||||||
|
from jinja2 import StrictUndefined, DictLoader
|
||||||
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
from rougail.annotator.variable import CONVERT_OPTION
|
||||||
|
from tiramisu.error import ValueWarning
|
||||||
|
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
|
||||||
|
global ENV, CONVERT_OPTION
|
||||||
|
kw = {}
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if '.' in key:
|
||||||
|
c_kw = kw
|
||||||
|
path, var = key.rsplit('.', 1)
|
||||||
|
for subkey in path.split('.'):
|
||||||
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
|
c_kw[var] = value
|
||||||
|
else:
|
||||||
|
kw[key] = value
|
||||||
|
values = ENV.get_template(__internal_jinja).render(kw, **func).strip()
|
||||||
|
convert = CONVERT_OPTION[__internal_type].get('func', str)
|
||||||
|
if __internal_multi:
|
||||||
|
return [convert(val) for val in values.split()]
|
||||||
|
values = convert(values)
|
||||||
|
return values if values != '' and values != 'None' else None
|
||||||
|
def variable_to_property(prop, value):
|
||||||
|
return prop if value else None
|
||||||
|
def jinja_to_property(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return func['variable_to_property'](prop, value is not None)
|
||||||
|
def jinja_to_property_help(prop, **kwargs):
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
return (prop, f'"{prop}" ({value})')
|
||||||
|
def valid_with_jinja(warnings_only=False, **kwargs):
|
||||||
|
global ValueWarning
|
||||||
|
value = func['jinja_to_function'](**kwargs)
|
||||||
|
if value:
|
||||||
|
if warnings_only:
|
||||||
|
raise ValueWarning(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(value)
|
||||||
|
func['jinja_to_function'] = jinja_to_function
|
||||||
|
func['jinja_to_property'] = jinja_to_property
|
||||||
|
func['jinja_to_property_help'] = jinja_to_property_help
|
||||||
|
func['variable_to_property'] = variable_to_property
|
||||||
|
func['valid_with_jinja'] = valid_with_jinja
|
||||||
|
dict_env = {}
|
||||||
|
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
|
||||||
|
ENV.filters = func
|
||||||
|
ENV.compile_templates('jinja_caches', zip=None)
|
||||||
|
option_5 = StrOption(name="var", doc="var", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
optiondescription_4 = OptionDescription(name="fam2", doc="fam2", children=[option_5], properties=frozenset({"standard"}))
|
||||||
|
option_7 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_5)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_6 = OptionDescription(name="fam1", doc="fam1", children=[option_7], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_3 = OptionDescription(name="general", doc="general", children=[optiondescription_4, optiondescription_6], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_3], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"}))
|
||||||
|
option_12 = StrOption(name="var", doc="var", default="no", properties=frozenset({"mandatory", "standard"}))
|
||||||
|
optiondescription_11 = OptionDescription(name="fam2", doc="fam2", children=[option_12], properties=frozenset({"standard"}))
|
||||||
|
option_14 = StrOption(name="var", doc="var", default=Calculation(func['calc_value'], Params((ParamOption(option_12)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "standard"}))
|
||||||
|
optiondescription_13 = OptionDescription(name="fam1", doc="fam1", children=[option_14], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_10 = OptionDescription(name="general", doc="general", children=[optiondescription_11, optiondescription_13], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_9 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_10], properties=frozenset({"standard"}))
|
||||||
|
optiondescription_8 = OptionDescription(name="2", doc="2", children=[optiondescription_9], properties=frozenset({"standard"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_8])
|
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
version: '1.0'
|
||||||
|
general:
|
||||||
|
variable:
|
||||||
|
variable2:
|
||||||
|
default:
|
||||||
|
type: jinja
|
||||||
|
jinja: '{{ information }}'
|
||||||
|
params:
|
||||||
|
information:
|
||||||
|
type: information
|
||||||
|
information: test_information
|
||||||
|
variable: _.variable
|
||||||
|
mandatory: false
|
|
@ -0,0 +1 @@
|
||||||
|
{"rougail.general.variable": "value"}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.general.variable": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"rougail.general.variable2": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": "value"
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue