File size: 745 Bytes
29046a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
def gradify_closure(func, argmaps, func_kwargs={}):
func_kwargs = dict(func_kwargs)
def gradify_func(*args):
kwargs = {}
for (arg, argmap) in zip(args, argmaps):
postprocessing = argmap.get("postprocessing", None)
if postprocessing:
arg = eval(postprocessing)(arg)
kw_label = argmap["label"]
kwargs[kw_label] = arg
return func(**kwargs, **func_kwargs)
return gradify_func
def compile_callable(source, target_name=None):
ldict = {}
exec(source, globals(), ldict)
if target_name:
return ldict[target_name]
else:
for v in ldict.values():
if callable(v):
return v |