From 972d264eee5105086e30df2a478e48a21f073832 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Wed, 16 Apr 2025 14:10:15 +0200 Subject: [PATCH] Started adding upper bound for the whiles --- src/call.py | 6 +++++- src/code_.py | 14 +++++++++++--- src/outils.py | 6 +++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/call.py b/src/call.py index be9135c..1f8bd77 100644 --- a/src/call.py +++ b/src/call.py @@ -209,10 +209,14 @@ class Call(Executor): #Step 1 -> get parameters tab_params, start, next_param = [], 0, None temp_param = param - while(start!=-1): + timeout = 0 + while(start!=-1 and timeout<constant.WHILE_UPPER_BOUND): temp_param = temp_param[start:] next_param, start = get_next_param(temp_param) tab_params.append(next_param.strip()) + timeout+=1 + if(timeout>=constant.WHILE_UPPER_BOUND): + raise BioFlowInsightError(f"The WHILE_UPPER_BOUND was exceeded. BioFlow-Insight was unable to extract the parameters for the call '{self.get_code(get_OG=True)}'. Make sure the workflow uses correct Nextflow syntaxe (https://www.nextflow.io/docs/latest/index.html).", type="Unable to extract call parameters") #Step 2 -> analyse paramters for param in tab_params: diff --git a/src/code_.py b/src/code_.py index 6a44399..5c315b9 100644 --- a/src/code_.py +++ b/src/code_.py @@ -45,8 +45,8 @@ class Code: quote_single, quote_double = False, False triple_single, triple_double = False, False - - while(start<len(code)): + timeout = 0 + while(start<len(code) and timeout<constant.WHILE_UPPER_BOUND): checked_triple = False if(start+3<=len(code)): if(code[start:start+3]=="'''" and not quote_single and not quote_double and not triple_single and not triple_double): @@ -116,6 +116,9 @@ class Code: start+=1 + timeout+=1 + if(timeout>=constant.WHILE_UPPER_BOUND): + raise BioFlowInsightError(f"The WHILE_UPPER_BOUND was exceeded. BioFlow-Insight was unable to turn a single line condition into a multi line condition. Make sure the workflow uses correct Nextflow syntaxe (https://www.nextflow.io/docs/latest/index.html).", type="Unable to turn single line condition into multi line") @@ -128,7 +131,8 @@ class Code: def remove_things_inside_map(self, code): index = 0 searching = True - while(searching): + timeout = 0 + while(searching and timeout<constant.WHILE_UPPER_BOUND): searching = False #TODO -> do the same with flatMap -> 668 for word in ["map", "flatMap"]: @@ -153,6 +157,10 @@ class Code: searching = True index+=1 break + timeout+=1 + if(timeout>=constant.WHILE_UPPER_BOUND): + raise BioFlowInsightError(f"The WHILE_UPPER_BOUND was exceeded. BioFlow-Insight was unable to extract the inside of a 'map' operator. Make sure the workflow uses correct Nextflow syntaxe (https://www.nextflow.io/docs/latest/index.html).", type="Unable to extract the inside of a 'map' operator") + return code diff --git a/src/outils.py b/src/outils.py index c941f71..83b420f 100644 --- a/src/outils.py +++ b/src/outils.py @@ -1,7 +1,7 @@ import re import subprocess import os -from .constant import WHILE_UPPER_BOUND +from . import constant from .bioflowinsighterror import BioFlowInsightError @@ -936,7 +936,7 @@ def extract_conditions(code, only_get_inside = True): timeout = 0 - while(start<len(code) and timeout < WHILE_UPPER_BOUND): + while(start<len(code) and timeout < constant.WHILE_UPPER_BOUND): checked_triple = False if(start+3<=len(code)): if(code[start:start+3]=="'''" and not quote_single and not quote_double and not triple_single and not triple_double): @@ -1061,7 +1061,7 @@ def extract_conditions(code, only_get_inside = True): start+=1 timeout+=1 - if(timeout>=WHILE_UPPER_BOUND): + if(timeout>=constant.WHILE_UPPER_BOUND): raise BioFlowInsightError("The WHILE_UPPER_BOUND was exceeded. BioFlow-Insight was unable to extarct the conditions. Make sure the workflow uses correct Nextflow syntaxe (https://www.nextflow.io/docs/latest/index.html).", type="Unable to extract conditions") for c in conditions_dico: start, end = conditions_dico[c] -- GitLab