diff --git a/src/workflow.py b/src/workflow.py index 16135f87713aa58164f0c6d2fac5c91c15feed60..49da4393ed0d3698a6d70bcc798640eda8bbcd77 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -541,6 +541,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #Replace old analysis with new analysis (simplified code) self.__init__(str(temp_file), display_info = False, duplicate=True, processes_2_remove=processes_2_remove) self.initialise() + os.remove(temp_file) self.graph.initialise(processes_2_remove = self.processes_2_remove) if(not self.graph.check_if_process_dependendy_is_equivalent_to_other_without_subworkflows(temp_process_dependency_graph)): if(render_graphs==True): @@ -1028,14 +1029,23 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #Replace names inside subworkflow subworkflow_code = f"workflow {name} {{\n{take}\nmain:\n{body}\n{emit}\n}}" + + #We do this so that the longest thing are rewritten first in the code -> to avoid problems + takes_param_2_length = {} + takes_param_2_new_param_names = {} for i in range(len(new_param_names)): - if(takes_param[i].get_code() != new_param_names[i]): + takes_param_2_new_param_names[takes_param[i].get_code()] = new_param_names[i] + takes_param_2_length[takes_param[i].get_code()] = len(takes_param[i].get_code()) + sorted_takes_param_2_length = {k: v for k, v in sorted(takes_param_2_length.items(), key=lambda item: item[1], reverse=True)} + for take_param in sorted_takes_param_2_length: + new_param = takes_param_2_new_param_names[take_param] + if(take_param != new_param): #pattern = fr"[\=\,\(] *({re.escape(takes_param[i].get_code())})[\s\,\)\.]" - pattern = fr"({re.escape(takes_param[i].get_code())})[\s\,\)\.]" + pattern = fr"({re.escape(take_param)})[\s\,\)\.]" temp = subworkflow_code - subworkflow_code = replace_group1(subworkflow_code, pattern, new_param_names[i]) + subworkflow_code = replace_group1(subworkflow_code, pattern, new_param) if(temp==subworkflow_code): - print(takes_param[i].get_code(), new_param_names[i]) + print(take_param, new_param) print(pattern) print(f'"{subworkflow_code}"') raise Exception("Something went wrong -> cause the paramter wasn't updated")