Commit 9a4a6231 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

No commit message

No commit message
parent 639c6ae4
......@@ -34,6 +34,8 @@ import jflow.utils as utils
from jflow.workflows_manager import WorkflowsManager, JFlowConfigReader
from jflow.parameter import Parameter, date
from inspect import getcallargs
from weaver.script import ABSTRACTIONS
from weaver.script import DATASETS
from weaver.script import FUNCTIONS
......@@ -101,16 +103,36 @@ class Workflow(threading.Thread):
def init_component_nameids(self):
for line in inspect.getsourcelines(getattr(self, self.function))[0]:
if line.find("self.add_component") != -1:
prefix = "default"
component_prefix = "default"
component_name = line.strip().split("self.add_component")[1][1:-1].split(",")[0][1:-1]
pre = re.search("self.add_component\s*\(\s*\"(\S+)\"\s*(,\s*(args\s*=\s*)?\[.*\]\s*)?((,\s*(kwargs\s*=\s*)?{.*}\s*)?(,\s*(component_prefix\s*=\s*)?\"(\S+)\"\s*\)?)?)", line)
if pre:
if pre.groups()[-1]: prefix = pre.groups()[-1]
if pre.groups()[0]: component_name = pre.groups()[0]
if self._component_is_duplicated(component_name+"."+prefix):
arguments = re.search("self.add_component\s*\((.+)\)", line).groups()[0]
named_prefix = re.search("component_prefix\s*=\s*([^,]+)", arguments)
# Component prefix is in named argument
if named_prefix:
component_prefix = named_prefix.groups()[0].strip().strip('"')
# Component prefix is missing or in unamed argument
else :
without_named_args = re.sub( ",?\s*\S+\s*=\s*\S+", "" , arguments) # Discard named arguments
fields = without_named_args.strip(",").split(",")
# Group brackets arguments
args_split_clean = []
current_idx = 0
current_arg = ""
while current_idx < len(fields) :
current_arg = current_arg + fields[current_idx] + ','
open_brackets = current_arg.count("[")
close_brackets = current_arg.count("]")
if open_brackets == close_brackets:
args_split_clean.append( current_arg[:-1] )
current_arg = ""
current_idx += 1
# Find component prefix
if len(args_split_clean) >= 4:
component_prefix = args_split_clean[3].strip().strip('"')
if self._component_is_duplicated(component_name+"."+component_prefix):
raise ValueError("Component " + component_name + " with prefix " +
prefix + " already exist in this pipeline!")
self.component_nameids[component_name+"."+prefix] = None
component_prefix + " already exist in this pipeline!")
self.component_nameids[component_name+"."+component_prefix] = None
@staticmethod
def config_parser(arg_line):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment