can add personal function

This commit is contained in:
2020-10-14 18:17:31 +02:00
parent 43e30bba47
commit 4b21b1507f
12 changed files with 102 additions and 9 deletions

View File

@ -596,7 +596,9 @@ class ConstraintAnnotator:
if not hasattr(objectspace.space, 'constraints'):
return
self.objectspace = objectspace
self.eosfunc = imp.load_source('eosfunc', eosfunc_file)
eosfunc = imp.load_source('eosfunc', eosfunc_file)
self.functions = dir(eosfunc)
self.functions.extend(INTERNAL_FUNCTIONS)
self.valid_enums = {}
if hasattr(self.objectspace.space.constraints, 'check'):
self.check_check()
@ -618,10 +620,8 @@ class ConstraintAnnotator:
def check_check(self):
remove_indexes = []
functions = dir(self.eosfunc)
functions.extend(INTERNAL_FUNCTIONS)
for check_idx, check in enumerate(self.objectspace.space.constraints.check):
if not check.name in functions:
if not check.name in self.functions:
raise DictConsistencyError(_('cannot find check function {}').format(check.name))
if hasattr(check, 'param'):
param_option_indexes = []
@ -1008,7 +1008,6 @@ class ConstraintAnnotator:
indexes = list(fills.keys())
indexes.sort()
targets = []
eosfunc = dir(self.eosfunc)
for idx in indexes:
fill = fills[idx]
# test if it's redefined calculation
@ -1016,7 +1015,7 @@ class ConstraintAnnotator:
raise DictConsistencyError(_(f"A fill already exists for the target: {fill.target}"))
targets.append(fill.target)
#
if fill.name not in eosfunc:
if fill.name not in self.functions:
raise DictConsistencyError(_('cannot find fill function {}').format(fill.name))
namespace = fill.namespace

View File

@ -44,13 +44,16 @@ class TiramisuReflector:
funcs_path,
):
self.storage = ElementStorage()
self.storage.text = ["try:",
self.storage.text = ["import imp",
f"func = imp.load_source('func', '{funcs_path}')",
"for key, value in dict(locals()).items():",
" if key != ['imp', 'func']:",
" setattr(func, key, value)",
"try:",
" from tiramisu3 import *",
"except:",
" from tiramisu import *",
"from rougail.tiramisu import ConvertDynOptionDescription",
"import imp",
f"func = imp.load_source('func', '{funcs_path}')",
]
self.make_tiramisu_objects(xmlroot)
# parse object