Skip to content

Commit

Permalink
Additional checks in pyfunc to remove arguments from initial list
Browse files Browse the repository at this point in the history
  • Loading branch information
awicenec committed May 25, 2022
1 parent a47cb17 commit 8afb9cd
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions daliuge-engine/dlg/apps/pyfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ def astparse(x):
kwargs = {}
self.pargs = []
pargsDict = collections.OrderedDict(zip(posargs,[None]*len(posargs))) # Initialize pargs dictionary
if "applicationArgs" in self.parameters:
appArgs = self.parameters["applicationArgs"] # we'll pop the identified ones
if ('outputs' in self.parameters and isinstance(self.parameters['outputs'][0], dict)):
out_names = [list(i.values())[0] for i in self.parameters['outputs']]
logger.debug(f"Using named ports to remove outputs from arguments: "+\
f"{out_names}")
_dum = [appArgs.pop(k) for k in out_names if k in appArgs]
if len(_dum) > 0:
logger.debug("Application arguments used as outputs removed : %s",
[i['text'] for i in _dum])

if ('inputs' in self.parameters and isinstance(self.parameters['inputs'][0], dict)):
logger.debug(f"Using named ports to identify inputs: "+\
f"{self.parameters['inputs']}")
Expand All @@ -447,34 +458,44 @@ def astparse(x):
for i in range(min(len(inputs),self.fn_nargs)):
kwargs.update({self.arguments.args[i]: list(inputs.values())[i]})

logger.debug(f"updating funcargs with input ports {kwargs}")
logger.debug(f"Updating funcargs with input ports {kwargs}")
self.funcargs.update(kwargs)
_dum = [appArgs.pop(k) for k in kwargs if k in appArgs]
logger.debug("Application arguments used as inputs removed: %s",
[i['text'] for i in _dum])

logger.debug("Found input ports matching posargs: %s", list(pargsDict.keys()))

# Try to get values for still missing positional arguments from Application Args
if "applicationArgs" in self.parameters:
appArgs = self.parameters["applicationArgs"] # we'll pop them
_dum = [appArgs.pop(k) for k in self.func_def_keywords if k in appArgs]
logger.debug("Identified keyword arguments removed: %s",
[i['text'] for i in _dum])
_dum = [appArgs.pop(k) for k in pargsDict if k in appArgs]
logger.debug("Identified positional arguments removed: %s",
[i['text'] for i in _dum])
for pa in posargs:
if pa not in self.funcargs:
if pa in appArgs and pa != 'self':
if pa != 'self' and pa not in self.funcargs:
if pa in appArgs:
arg = appArgs.pop(pa)
value = arg['value']
ptype = arg['type']
if ptype in ["Complex", "Json"]:
try:
value = ast.literal_eval(value)
except ValueError:
pass
except Exception as e:
# just go on if this did not work
logger.warning("Eval raised an error: %s",e)
elif ptype in ["Python"]:
try:
import numpy
value = eval(value, {"numpy": numpy}, {})
except:
pass
pargsDict.update({pa: value})
elif pa != 'self':
elif pa != 'self' and pa not in pargsDict:
logger.warning(f"Required positional argument '{pa}' not found!")
logger.debug(f"updating posargs with {list(kwargs.values())}")
logger.debug(f"updating posargs with {list(pargsDict.keys())}")
self.pargs.extend(list(pargsDict.values()))

# Try to get values for still missing kwargs arguments from Application kws
Expand Down

0 comments on commit 8afb9cd

Please sign in to comment.