WIP: Expand the developer documentation #27
3 changed files with 27 additions and 10 deletions
|
@ -332,6 +332,7 @@ class JinjaCalculation(Calculation):
|
||||||
}
|
}
|
||||||
if self.version != "1.0":
|
if self.version != "1.0":
|
||||||
default["params"][true_path]["propertyerror"] = False
|
default["params"][true_path]["propertyerror"] = False
|
||||||
|
default["params"][true_path]["optional"] = True
|
||||||
if identifier:
|
if identifier:
|
||||||
default["params"][true_path]["identifier"] = identifier
|
default["params"][true_path]["identifier"] = identifier
|
||||||
return default
|
return default
|
||||||
|
@ -441,6 +442,8 @@ class _VariableCalculation(Calculation):
|
||||||
"variable": variable,
|
"variable": variable,
|
||||||
"propertyerror": self.propertyerror,
|
"propertyerror": self.propertyerror,
|
||||||
}
|
}
|
||||||
|
if isinstance(self, VariableCalculation) and self.optional:
|
||||||
|
param["optional"] = self.optional
|
||||||
if identifier:
|
if identifier:
|
||||||
param["identifier"] = identifier
|
param["identifier"] = identifier
|
||||||
params = {None: [param]}
|
params = {None: [param]}
|
||||||
|
@ -490,6 +493,12 @@ class _VariableCalculation(Calculation):
|
||||||
raise DictConsistencyError(msg, 21, self.xmlfiles)
|
raise DictConsistencyError(msg, 21, self.xmlfiles)
|
||||||
else:
|
else:
|
||||||
params[None][0]["index"] = {"index": {"type": "index"}}
|
params[None][0]["index"] = {"index": {"type": "index"}}
|
||||||
|
if self.path in objectspace.followers:
|
||||||
|
multi = objectspace.multis[self.path] == "submulti"
|
||||||
|
else:
|
||||||
|
multi = self.path in objectspace.multis
|
||||||
|
if multi:
|
||||||
|
params["__internal_multi"] = True
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
@ -519,7 +528,8 @@ class VariableCalculation(_VariableCalculation):
|
||||||
|
|
||||||
|
|
||||||
class VariablePropertyCalculation(_VariableCalculation):
|
class VariablePropertyCalculation(_VariableCalculation):
|
||||||
attribute_name: Literal[*PROPERTY_ATTRIBUTE]
|
# For python 3.9 attribute_name: Literal[*PROPERTY_ATTRIBUTE]
|
||||||
|
attribute_name: Literal["frozen", "hidden", "disabled", "mandatory"]
|
||||||
when: Any = undefined
|
when: Any = undefined
|
||||||
when_not: Any = undefined
|
when_not: Any = undefined
|
||||||
|
|
||||||
|
@ -640,7 +650,8 @@ class IdentifierCalculation(_IdentifierCalculation):
|
||||||
|
|
||||||
|
|
||||||
class IdentifierPropertyCalculation(_IdentifierCalculation):
|
class IdentifierPropertyCalculation(_IdentifierCalculation):
|
||||||
attribute_name: Literal[*PROPERTY_ATTRIBUTE]
|
# for python 3.9 attribute_name: Literal[*PROPERTY_ATTRIBUTE]
|
||||||
|
attribute_name: Literal["frozen", "hidden", "disabled", "mandatory"]
|
||||||
when: Any = undefined
|
when: Any = undefined
|
||||||
when_not: Any = undefined
|
when_not: Any = undefined
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
try:
|
|
||||||
from tiramisu5 import DynOptionDescription, calc_value
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
from tiramisu import DynOptionDescription, calc_value
|
|
||||||
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
from importlib.machinery import SourceFileLoader as _SourceFileLoader
|
||||||
from importlib.util import (
|
from importlib.util import (
|
||||||
spec_from_loader as _spec_from_loader,
|
spec_from_loader as _spec_from_loader,
|
||||||
|
@ -40,8 +36,8 @@ from jinja2 import StrictUndefined, DictLoader
|
||||||
from jinja2.sandbox import SandboxedEnvironment
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
from rougail.object_model import CONVERT_OPTION
|
from rougail.object_model import CONVERT_OPTION
|
||||||
from rougail.error import display_xmlfiles
|
from rougail.error import display_xmlfiles
|
||||||
from tiramisu import function_waiting_for_error
|
from tiramisu import DynOptionDescription, calc_value, function_waiting_for_error
|
||||||
from tiramisu.error import ValueWarning, ConfigError, PropertiesOptionError
|
from tiramisu.error import ValueWarning, ConfigError, PropertiesOptionError, CancelParam
|
||||||
from .utils import normalize_family
|
from .utils import normalize_family
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,8 +98,10 @@ def load_functions(path):
|
||||||
func[function] = getattr(func_, function)
|
func[function] = getattr(func_, function)
|
||||||
|
|
||||||
|
|
||||||
def rougail_calc_value(*args, __default_value=None, **kwargs):
|
def rougail_calc_value(*args, __default_value=None, __internal_multi=False, **kwargs):
|
||||||
values = calc_value(*args, **kwargs)
|
values = calc_value(*args, **kwargs)
|
||||||
|
if values is None and __internal_multi:
|
||||||
|
values = []
|
||||||
if __default_value is not None and values in [None, []]:
|
if __default_value is not None and values in [None, []]:
|
||||||
return __default_value
|
return __default_value
|
||||||
return values
|
return values
|
||||||
|
@ -128,9 +126,13 @@ def jinja_to_function(
|
||||||
if "." in key:
|
if "." in key:
|
||||||
c_kw = kw
|
c_kw = kw
|
||||||
path, var = key.rsplit(".", 1)
|
path, var = key.rsplit(".", 1)
|
||||||
|
if isinstance(value, CancelParam):
|
||||||
|
count_o_path = value.origin_path.count('.') - value.current_path.count('.')
|
||||||
|
path = path.rsplit(".", count_o_path)[0]
|
||||||
for subkey in path.split("."):
|
for subkey in path.split("."):
|
||||||
c_kw = c_kw.setdefault(subkey, {})
|
c_kw = c_kw.setdefault(subkey, {})
|
||||||
c_kw[var] = value
|
if not isinstance(value, CancelParam):
|
||||||
|
c_kw[var] = value
|
||||||
else:
|
else:
|
||||||
if key in kw:
|
if key in kw:
|
||||||
raise ConfigError(
|
raise ConfigError(
|
||||||
|
|
|
@ -339,6 +339,7 @@ class Common:
|
||||||
return self.build_option_param(
|
return self.build_option_param(
|
||||||
param["variable"],
|
param["variable"],
|
||||||
param.get("propertyerror", True),
|
param.get("propertyerror", True),
|
||||||
|
param.get("optional", False),
|
||||||
param.get("identifier"),
|
param.get("identifier"),
|
||||||
param.get("dynamic"),
|
param.get("dynamic"),
|
||||||
param.get("whole", False),
|
param.get("whole", False),
|
||||||
|
@ -355,6 +356,7 @@ class Common:
|
||||||
self,
|
self,
|
||||||
variable,
|
variable,
|
||||||
propertyerror,
|
propertyerror,
|
||||||
|
optional: bool,
|
||||||
identifier: Optional[str],
|
identifier: Optional[str],
|
||||||
dynamic,
|
dynamic,
|
||||||
whole: bool,
|
whole: bool,
|
||||||
|
@ -377,6 +379,8 @@ class Common:
|
||||||
ident = self.convert_str(ident)
|
ident = self.convert_str(ident)
|
||||||
identifiers.append(str(ident))
|
identifiers.append(str(ident))
|
||||||
params.append("[" + ", ".join(identifiers) + "]")
|
params.append("[" + ", ".join(identifiers) + "]")
|
||||||
|
if optional:
|
||||||
|
params.append("optional=True")
|
||||||
else:
|
else:
|
||||||
param_type = "ParamOption"
|
param_type = "ParamOption"
|
||||||
if not propertyerror:
|
if not propertyerror:
|
||||||
|
|
Loading…
Reference in a new issue