diff --git a/src/outils.py b/src/outils.py index 4337c1acdae66b4b70257f8c552a5c9902c218e2..0197475ff2a4f03137ed5f65e9b6db9319d0a4ab 100644 --- a/src/outils.py +++ b/src/outils.py @@ -919,7 +919,7 @@ def is_git_directory(path = '.'): #Function that extracts the conditions defined in some code #TODO -> need to update this -> if the same condition appears multiple times in the code -> in the dico it is only counted once #Right now the function is not recursif -> since i call blocks recursively and that this function is only used by blocks -> it is indirectrly called recursiverly -def extract_conditions(code): +def extract_conditions(code, only_get_inside = True): conditions_dico = {} index_condition = 0 @@ -998,7 +998,10 @@ def extract_conditions(code): conditions.append(condition) end = extract_curly(code, match.span(0)[1]+start)#Here we nedd to add the start index since we're only working on a subpart of code start_inside, end_inside = match.span(0)[1]+start, end-1 - conditions_dico[f"{condition}$$__$${index_condition}"] = (start_inside, end_inside) + if(only_get_inside): + conditions_dico[f"{condition}$$__$${index_condition}"] = (start_inside, end_inside) + else: + conditions_dico[f"{condition}$$__$${index_condition}"] = (start, end) index_condition+=1 #conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) break @@ -1018,7 +1021,10 @@ def extract_conditions(code): start_else+=end end_else = extract_curly(code, end_else+end) start_inside, end_inside = match.span(0)[1]+end, end_else-1 - conditions_dico[f"{condition}$$__$${index_condition}"] = (start_inside, end_inside) + if(only_get_inside): + conditions_dico[f"{condition}$$__$${index_condition}"] = (start_inside, end_inside) + else: + conditions_dico[f"{condition}$$__$${index_condition}"] = (start_else, end_else) index_condition+=1 #conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) break @@ -1030,7 +1036,10 @@ def extract_conditions(code): end_else = extract_curly(code, end_else+end) start_inside, end_inside = match.span(0)[1]+end, end_else-1 condition = ' && '.join(["!({})".format(v) for v in conditions]) - conditions_dico[f"{condition}$$__$${index_condition}"] = (start_inside, end_inside) + if(only_get_inside): + conditions_dico[f"{condition}$$__$${index_condition}"] = (start_inside, end_inside) + else: + conditions_dico[f"{condition}$$__$${index_condition}"] = (start_else, end_else) index_condition+=1 #conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) diff --git a/src/workflow.py b/src/workflow.py index ca173289357c17b687b97f4d7d098afe8ebb82a1..777d01a5833e5d4527452e5e16369d6d5bd39a1c 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -34,7 +34,7 @@ class Workflow: processes_2_remove: A string indicating the processes to remove from the workflow """ - def __init__(self, file, duplicate=False, display_info=True, output_dir = './results', + def __init__(self, file, duplicate=True, display_info=True, output_dir = './results', name = None, processes_2_remove = None): @@ -661,12 +661,15 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen if(self.duplicate): code = self.simplify_workflow_code() + print(code) self.rewrite_and_initialise(code) #Get the clusters and the code self.check_relevant_processes_in_workflow(relevant_processes) + print("started Generating first user view") self.generate_user_view(relevant_processes = relevant_processes, processes_2_remove = []) clusters = self.graph.get_clusters_from_user_view() + print("Generated first user view") #DETERMING WHICH SUBWORKFLOWS ARE BROKEN WITH THE CLUSTER #Creating the clusters with calls instead of processes or subworkflows @@ -732,6 +735,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #Get the clusters and the code self.generate_user_view(relevant_processes = relevant_processes, processes_2_remove = []) clusters = self.graph.get_clusters_from_user_view() + print("Generated second user view") #Get the clsuters with the corresponding operations inside #for i in range(len(clusters)): @@ -803,7 +807,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #else: code = code.replace(call.get_code(get_OG = True), "") - + processes_added.append(call.get_first_element_called()) values = [] for condition in call.get_all_conditions(): @@ -814,6 +818,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen else: body+=f"\n{call.get_code()}\n" things_added_in_cluster.append(call) + #Below elif(ele.get_type()=="Operation"): #TODO -> check this verification there might be some "effet de bord" @@ -866,20 +871,27 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #TODO find a better naming system name = f"non_relevant_cluster_{non_relevant_name}" non_relevant_name+=1 - + #Check that there is a single condtion in the body body = group_together_ifs(body) conditions_in_subworkflow = [] - end = -1 - for match in re.finditer(r"if\s*(\([^\{]+)\{", body): - conditions_in_subworkflow.append(match.group(1).strip()) - _, start = match.span(0) - - if(len(conditions_in_subworkflow)==1): - end = extract_curly(body, start) - body = body[start: end-1].strip() + temp_body = body + conditions_in_subworkflow_2 = extract_conditions(temp_body, only_get_inside = False) - + if(len(conditions_in_subworkflow_2)==1): + for condition in conditions_in_subworkflow_2: + start, end = conditions_in_subworkflow_2[condition] + temp_body = temp_body.replace(temp_body[start: end], "") + #This means that there is only one codnition with all the executors in the condition + if(temp_body.strip()==""): + conditions_in_subworkflow = extract_conditions(body) + for condition in conditions_in_subworkflow: + start, end = conditions_in_subworkflow[condition] + body = body[start: end-1].strip() + conditions_in_subworkflow = list(conditions_in_subworkflow.keys()) + + + #TAKE #Adding take parameters on the inside of the subworkflow takes_param = self.get_takes(things_added_in_cluster) @@ -913,11 +925,11 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen temp = '\n'.join(old_output_names) emit = f"\nemit:\n{temp}\n" + #Adding empty channels if it doesn't exist in the case of a negative condition body = get_channels_to_add_in_false_conditions(body, old_output_names) - #Replace names inside subworkflow subworkflow_code = f"workflow {name} {{\n{take}\nmain:\n{body}\n{emit}\n}}" for i in range(len(new_param_names)): @@ -942,8 +954,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen channels_to_replace_outside_of_cluster.append((old_output_names[i], param_out_name)) #If there was only one single condition in the subworkflow cluster -> then we add it when the call is done if(len(conditions_in_subworkflow)==1): - subworkfow_call = f"if{conditions_in_subworkflow[0]} {{\n{subworkfow_call_case_true}\n}} else {{\n{subworkfow_call_case_false}\n}}" - None + subworkfow_call = f"if({conditions_in_subworkflow[0].split('$$__$$')[0]}) {{\n{subworkfow_call_case_true}\n}} else {{\n{subworkfow_call_case_false}\n}}" else: subworkfow_call = subworkfow_call_case_true