Skip to content
Snippets Groups Projects
Commit 8ae5e926 authored by George Marchment's avatar George Marchment
Browse files

added recursive functionnality for the external script call

parent 964e2292
No related branches found
No related tags found
No related merge requests found
Pipeline #13921 passed with stage
in 1 minute and 4 seconds
...@@ -24,6 +24,7 @@ class Process(Nextflow_Building_Blocks): ...@@ -24,6 +24,7 @@ class Process(Nextflow_Building_Blocks):
self.tools = [] self.tools = []
self.modules = [] self.modules = []
self.commands = [] self.commands = []
self.external_scripts = [-1]
self.initialise() self.initialise()
self.initialised = True self.initialised = True
...@@ -55,21 +56,24 @@ class Process(Nextflow_Building_Blocks): ...@@ -55,21 +56,24 @@ class Process(Nextflow_Building_Blocks):
return self.tools return self.tools
def get_external_scripts_call(self): def get_external_scripts_call(self, code):
code = self.get_script_code()
tab = [] tab = []
for match in re.finditer(r"([^\s\\\*\{\}\[\]]+\.(sh|py|R|r|pl|rg))[^\w]", code): for match in re.finditer(r"(\s|\/)([\w\_\-\&]+\/)*([\w\_\-\&]+)\.(sh|py|R|r|pl|rg)", code):
tab.append(match.group(1)) tab.append(match.group(0).strip())
return list(set(tab)) return list(set(tab))
def get_external_scripts_code(self): def initialise_external_scripts_code(self, code, extension = "", previously_called = {}):
calls = self.get_external_scripts_call() calls = self.get_external_scripts_call(code+'\n')
#workflow_directory = self.origin.get_address() #workflow_directory = self.origin.get_address()
#print(workflow_directory) #print(workflow_directory)
#import os #import os
#print(os.getcwd(), self.origin.get_address(), self.get_workflow_address()) #print(os.getcwd(), self.origin.get_address(), self.get_workflow_address())
scripts = [] scripts = []
extensions = []
bash_scripts = []
tab = []
for call in calls: for call in calls:
#Check first if the file is in the bin #Check first if the file is in the bin
file = glob.glob(f'{self.get_workflow_address()}/bin/**/{call}', recursive=True) file = glob.glob(f'{self.get_workflow_address()}/bin/**/{call}', recursive=True)
...@@ -80,14 +84,32 @@ class Process(Nextflow_Building_Blocks): ...@@ -80,14 +84,32 @@ class Process(Nextflow_Building_Blocks):
file = glob.glob(f'{self.get_workflow_address()}/**/{call}', recursive=True) file = glob.glob(f'{self.get_workflow_address()}/**/{call}', recursive=True)
if(len(file)>1): if(len(file)>1):
raise BioFlowInsightError(f"More than one script named '{call}' in the workflow source code, don't know which one to use when using the process '{self.get_name()}'", num = 13, origin=self) raise BioFlowInsightError(f"More than one script named '{call}' in the workflow source code, don't know which one to use when using the process '{self.get_name()}'", num = 13, origin=self)
for f in file: for f in file:
with open(f, 'r') as s: if(f not in previously_called):
scripts.append(s.read()) val = ""
with open(f, 'r', encoding='latin-1') as s:
#with open(f, 'r') as s:
val = s.read()
scripts.append(val)
previously_called[f] = ""
#Recursive Call to get the ones which are being called if the current file is a bash script
if(extension not in ["py", "R", "pl", "rg", "r"]):
tab += self.initialise_external_scripts_code(val, extension=f.split(".")[-1], previously_called= previously_called)
scripts+=tab
return scripts return list(set(scripts))
def get_external_scripts_code(self):
if(self.external_scripts!=[-1]):
None
else:
self.external_scripts = self.initialise_external_scripts_code(self.get_script_code())
return self.external_scripts
def get_python_packages_imported_internal_script(self): def get_python_packages_imported_internal_script(self):
packages = [] packages = []
packages+= get_python_packages(self.get_script_code()) packages+= get_python_packages(self.get_script_code())
...@@ -95,7 +117,8 @@ class Process(Nextflow_Building_Blocks): ...@@ -95,7 +117,8 @@ class Process(Nextflow_Building_Blocks):
def get_python_packages_imported_external_scripts(self): def get_python_packages_imported_external_scripts(self):
packages = [] packages = []
for s in self.get_external_scripts_code(): external_scripts = self.get_external_scripts_code()
for s in external_scripts:
packages+= get_python_packages(s) packages+= get_python_packages(s)
return packages return packages
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment