diff --git a/src/call.py b/src/call.py index def00263a1dd89c28237effa3188e6a999669d47..ebe16efc5f75a29591377a3b97a00dfbf087e91e 100644 --- a/src/call.py +++ b/src/call.py @@ -118,7 +118,9 @@ class Call(Executor): if(len(lines)==1): new_bit = f"{param_new_name} = {lines[0]}" else: - if(re.fullmatch(r"\w+", lines[-1].strip())): + #If there is no '=' -> it means it's a single emit or channel + if(lines[-1].strip().find('=')==-1): + #if(re.fullmatch(r"\w+", lines[-1].strip())): head = '\n'.join(lines[:-1]) new_bit = f"{head}\n{param_new_name} = {lines[-1]}" else: diff --git a/src/code_.py b/src/code_.py index 79683779e6243d8cba624e03b4e1a0e732485714..079e16765819da79671947dff3ac9a39c9fb8beb 100644 --- a/src/code_.py +++ b/src/code_.py @@ -135,7 +135,7 @@ class Code: start_map, end = match.span(0) end_map = extract_curly(code, end) old = code[start_map:end_map] - new_code = f".{word}_modified {{ '''\n{code[end:end_map-1]}\n''' }}" + new_code = f".{word}_modified {{ ¤'''\n{code[end:end_map-1]}\n'''¤ }}" code = code.replace(old, new_code) searching = True break diff --git a/src/outils_graph.py b/src/outils_graph.py index acce374f82d0d686cba66fe22aa276143d6d9625..3248fe725d2a53d3c8356e13628bb8c40a988c70 100644 --- a/src/outils_graph.py +++ b/src/outils_graph.py @@ -35,13 +35,16 @@ def add_nodes(dot, dico, label_node = True): #dot.node(n["id"], "", shape="circle", fillcolor=fillcolor, color = color, style="filled") dot.node(n["id"], n["name"], shape=n["shape"], xlabel= xlabel, fillcolor=fillcolor, color = color, style="filled") else: - #dot.node(n["id"], "", shape="circle", fillcolor=fillcolor, color = color, style="filled") - dot.node(n["id"], n["name"], shape=n["shape"], fillcolor=fillcolor, color=color, style="filled") + dot.node(n["id"], "", shape=n["shape"], fillcolor=fillcolor, color = color, style="filled") + #dot.node(n["id"], n["name"], shape=n["shape"], fillcolor=fillcolor, color=color, style="filled") for sub in dico["subworkflows"]: with dot.subgraph(name="cluster"+sub) as c: add_nodes(c, dico["subworkflows"][sub], label_node = label_node) - c.attr(label=sub) + if(label_node): + c.attr(label=sub) + else: + c.attr(label="") def add_edges(dot, dico, label_edge = True): for e in dico["edges"]: @@ -136,14 +139,22 @@ def fill_dot_2(dot, dico, label_node = True, label_edge = True): fill_dot(c, dico["subworkflows"][sub], label_node, label_edge) c.attr(label=sub) +def generate_pos_graph(filename, dico, relevant_nodes = -1): + dot = graphviz.Digraph() + fill_dot(dot, dico, False, False) + dot.format = 'dot' + dot.render(filename=f'{filename}_pos', outfile=f'{filename}_pos.png') + + def generate_graph_dot(filename, dico, label_node = True, label_edge = True, render_graphs = True, relevant_nodes = -1): + generate_pos_graph(filename, dico, relevant_nodes) #dot = graphviz.Digraph(filename=filename, format='png', comment="temp") dot = graphviz.Digraph() if(relevant_nodes==-1): - fill_dot(dot, dico, label_node, label_edge) + fill_dot(dot, dico, True, label_edge) else: - fill_dot(dot, dico, label_node, label_edge) + fill_dot(dot, dico, True, label_edge) #metro_dot(dot, dico, relevant_nodes = relevant_nodes) dot.save(filename=f'{filename}.dot') #dot.format = 'dot' diff --git a/src/workflow.py b/src/workflow.py index 09be46ea695a9664145a0e33dd9625a47c7a89ce..985858c8f31e6fc6f664e1ce6319989fb982dc04 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -364,6 +364,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #Putting || back code = code.replace("$OR$", "||") + #TODO -> add the other things necessary to reformat code #Somethimes this is incorrect but that's due to the fact that the DSL1 analysis isn't as clean as the DSL2 analyse (concerning the conditions) #What i mean that when searching for channels, DSL1 doesn't consider the conditions when searching from the processes while DSL2 does @@ -444,6 +445,18 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen old = ternary_operation_dico[new] code = code.replace(new.strip(), old) return code + + def put_modified_operations_back(self, code): + searching = True + while(searching): + searching = False + for match in re.finditer(r"\.(\w+)_modified\s*\{\s*¤\'\'\'([^¤]+)¤\s*\}", code): + operator = match.group(1) + inside = match.group(2)[2:-3]#Cause we want to remove the extras '''...''' + code = code.replace(match.group(0), f".{operator} {{ {inside} }}") + searching = True + break + return code #TODO -> write tests for this method @@ -1152,6 +1165,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #Putting || back code = self.put_back_old_ternary_operations(code, ternary_operation_dico) code = code.replace("$OR$", "||") + code = self.put_modified_operations_back(code) code = remove_extra_jumps(format_with_tabs(code)) f = open(self.get_output_dir()/ "debug" / "rewritten.nf", "w") f.write(code)