From ba7c4522f6c3ceb65635418b7948c7b873654c5f Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Mon, 2 Dec 2024 15:58:35 +0100
Subject: [PATCH] Just cleaning up a bit

---
 src/bioflowinsighterror.py |  1 -
 src/condition.py           |  2 ++
 src/include.py             |  2 --
 src/main_DSL2.py           |  9 ++++++++-
 src/nextflow_file.py       | 15 +++++++--------
 src/outils.py              |  2 --
 6 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/bioflowinsighterror.py b/src/bioflowinsighterror.py
index a948908..f7490de 100644
--- a/src/bioflowinsighterror.py
+++ b/src/bioflowinsighterror.py
@@ -11,7 +11,6 @@ class BioFlowInsightError(Exception):
     """
     def __init__(self, error, num, origin = None):
         self.origin = origin
-        #TODO -> add message at the end
         if(origin!=None):
             super().__init__(f"[{num}] Error in the file '{self.origin.get_file_address()}': "+error)
         else:
diff --git a/src/condition.py b/src/condition.py
index da5da03..34a1fcb 100644
--- a/src/condition.py
+++ b/src/condition.py
@@ -16,6 +16,8 @@ class Condition:
 
         
         conditions_dico = self.origin.get_file_conditions()
+        #conditions_dico_temp = extract_conditions(code)
+        #print(conditions_dico==conditions_dico_temp)
         pos = code.find(thing_defined)
         for c in conditions_dico:
             condition_extend = conditions_dico[c]
diff --git a/src/include.py b/src/include.py
index 3ff4fff..35ccf9d 100644
--- a/src/include.py
+++ b/src/include.py
@@ -125,8 +125,6 @@ class Include(Nextflow_Building_Blocks):
                     for match in re.finditer(pattern_as, include):
                         found = True
                         if(self.get_duplicate_status()):
-                            #TODO -> try shallow copy too
-                            #thing_as = copy.copy(self.file.get_element_from_name(match.group(1)))
                             thing_as = copy.deepcopy(self.file.get_element_from_name(match.group(1)))
                             thing_as.set_alias(match.group(3))
                             self.defines.append(thing_as)
diff --git a/src/main_DSL2.py b/src/main_DSL2.py
index ecde61b..7360194 100644
--- a/src/main_DSL2.py
+++ b/src/main_DSL2.py
@@ -1,23 +1,30 @@
 from .nextflow_building_blocks import Nextflow_Building_Blocks
 from .bioflowinsighterror import BioFlowInsightError
 import re
-from .outils import get_dico_from_tab_from_id
+from .outils import get_dico_from_tab_from_id, extract_conditions
 
 from . import constant
 
 
+
 class Main_DSL2(Nextflow_Building_Blocks):
     def __init__(self, code, origin):
         Nextflow_Building_Blocks.__init__(self, code)
         self.origin = origin
         self.calls = []
         self.initialised = False
+        self.conditions=None
 
     def get_channels(self):
         return self.channels
     
     def get_workflow_code(self):
         return self.get_code()
+    
+    def get_file_conditions(self):
+        if(self.conditions==None):
+            self.conditions = extract_conditions(self.get_code())
+        return self.conditions
 
     def get_type(self):
         return "Main DSL2"
diff --git a/src/nextflow_file.py b/src/nextflow_file.py
index e199cf5..f4112fd 100644
--- a/src/nextflow_file.py
+++ b/src/nextflow_file.py
@@ -37,9 +37,8 @@ class Nextflow_File(Nextflow_Building_Blocks):
         if(self.first_file==True):
             self.origin.set_DSL(self.which_DSL())
         self.graph = None
-        self.conditions = extract_conditions(self.get_code())
-        
         self.added_2_rocrate = False
+        self.conditions=None
         self.check_file_correctness()
         self.do_start_stuff()
         #self.extract_metadata()
@@ -55,6 +54,8 @@ class Nextflow_File(Nextflow_Building_Blocks):
         return self.get_code()
 
     def get_file_conditions(self):
+        if(self.conditions==None):
+            self.conditions = extract_conditions(self.get_code())
         return self.conditions
 
 
@@ -237,16 +238,14 @@ class Nextflow_File(Nextflow_Building_Blocks):
     def which_DSL(self):
         DSL = "DSL2"
         #If there are include
-        self.extract_includes()
-        if(len(self.includes)>0):
+        pattern = constant.FULL_INLCUDE_2
+        for match in re.finditer(pattern, self.get_code()):
             return DSL
         #If there are subworkflows
-        self.extract_subworkflows()
-        if(len(self.subworkflows)>0):
+        for match in re.finditer(constant.SUBWORKFLOW_HEADER, self.get_code()):
             return DSL
         #If there is the main
-        self.extract_main()
-        if(self.main!=None):
+        for match in re.finditer(constant.WORKFLOW_HEADER_2, '\n'+self.get_code()+'\n'):
             return DSL
         #Analyse the processes
         self.extract_processes()
diff --git a/src/outils.py b/src/outils.py
index c4004c6..3b7bc90 100644
--- a/src/outils.py
+++ b/src/outils.py
@@ -975,9 +975,7 @@ def extract_conditions(code):
                 if(code[start-1]!="\\" or (code[start-1]=="\\" and code[start-2]=="\\")):
                     quote_double=False
 
-            #TODO add "else if" compatibaliaty 
             #TODO Right now -> support only for if/else written with curlies -> not on single line
-
             def adding_inside(conditions_dico, code, start_inside, end_inside):
                 temp_dico = extract_conditions(code[start_inside:end_inside])
                 for c in temp_dico:
-- 
GitLab