44import json
55import logging
66import os
7- from subprocess import DEVNULL , CalledProcessError , check_call
7+ import sys
8+ from subprocess import DEVNULL , CalledProcessError , check_call # nosec B404
89from typing import Any , Dict , List , Optional , Set , Tuple , Union , cast
910from urllib .request import pathname2url , urlopen
1011
1819def py3_compatible (filePath : str ) -> bool :
1920 """Determines if a python file is 3.x compatible by seeing if it compiles in a subprocess"""
2021 try :
21- check_call (["python3" , "-m" , "py_compile" , filePath ], stderr = DEVNULL )
22+ check_call (
23+ [sys .executable , "-m" , "py_compile" , os .path .normpath (filePath )],
24+ stderr = DEVNULL ,
25+ ) # nosec B603
2226 except CalledProcessError as e :
2327 raise RuntimeError ("Python files must be 3.x compatible" ) from e
2428 return True
@@ -29,9 +33,7 @@ def get_version(extension: str, workflow_file: str) -> str:
2933 if extension == "py" and py3_compatible (workflow_file ):
3034 return "3"
3135 elif extension == "cwl" :
32- return cast (
33- str , yaml .load (open (workflow_file ), Loader = yaml .FullLoader )["cwlVersion" ]
34- )
36+ return cast (str , yaml .safe_load (open (workflow_file ))["cwlVersion" ])
3537 else : # Must be a wdl file.
3638 # Borrowed from https://github.com/Sage-Bionetworks/synapse-orchestrator/
3739 # blob/develop/synorchestrator/util.py#L142
@@ -66,7 +68,7 @@ def wf_info(workflow_path: str) -> Tuple[str, str]:
6668 "http://"
6769 ):
6870 # If file not local go fetch it.
69- html = urlopen (workflow_path ).read ()
71+ html = urlopen (workflow_path ).read () # nosec B310
7072 local_loc = os .path .join (os .getcwd (), "fetchedFromRemote." + file_type )
7173 with open (local_loc , "w" ) as f :
7274 f .write (html .decode ())
@@ -174,7 +176,7 @@ def build_wes_request(
174176 attach_f : Any = open (attachment , "rb" )
175177 relpath = os .path .relpath (attachment , wfbase )
176178 elif attachment .startswith ("http" ):
177- attach_f = urlopen (attachment )
179+ attach_f = urlopen (attachment ) # nosec B310
178180 relpath = os .path .basename (attach_f )
179181
180182 parts .append (("workflow_attachment" , (relpath , attach_f )))
@@ -226,7 +228,7 @@ def get_service_info(self) -> Dict[str, Any]:
226228 :param host: Port where the post request will be sent and the wes server listens at (default 8080)
227229 :return: The body of the get result as a dictionary.
228230 """
229- postresult = requests .get (
231+ postresult = requests .get ( # nosec B113
230232 f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/service-info" ,
231233 headers = self .auth ,
232234 )
@@ -244,7 +246,7 @@ def list_runs(self) -> Dict[str, Any]:
244246 :param host: Port where the post request will be sent and the wes server listens at (default 8080)
245247 :return: The body of the get result as a dictionary.
246248 """
247- postresult = requests .get (
249+ postresult = requests .get ( # nosec B113
248250 f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs" , headers = self .auth
249251 )
250252 return wes_reponse (postresult )
@@ -266,7 +268,7 @@ def run(
266268 """
267269 attachments = list (expand_globs (attachments ))
268270 parts = build_wes_request (wf , jsonyaml , attachments )
269- postresult = requests .post (
271+ postresult = requests .post ( # nosec B113
270272 f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs" ,
271273 files = parts ,
272274 headers = self .auth ,
@@ -283,7 +285,7 @@ def cancel(self, run_id: str) -> Dict[str, Any]:
283285 :param host: Port where the post request will be sent and the wes server listens at (default 8080)
284286 :return: The body of the delete result as a dictionary.
285287 """
286- postresult = requests .post (
288+ postresult = requests .post ( # nosec B113
287289 f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs/{ run_id } /cancel" ,
288290 headers = self .auth ,
289291 )
@@ -299,7 +301,7 @@ def get_run_log(self, run_id: str) -> Dict[str, Any]:
299301 :param host: Port where the post request will be sent and the wes server listens at (default 8080)
300302 :return: The body of the get result as a dictionary.
301303 """
302- postresult = requests .get (
304+ postresult = requests .get ( # nosec B113
303305 f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs/{ run_id } " ,
304306 headers = self .auth ,
305307 )
@@ -315,7 +317,7 @@ def get_run_status(self, run_id: str) -> Dict[str, Any]:
315317 :param host: Port where the post request will be sent and the wes server listens at (default 8080)
316318 :return: The body of the get result as a dictionary.
317319 """
318- postresult = requests .get (
320+ postresult = requests .get ( # nosec B113
319321 f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs/{ run_id } /status" ,
320322 headers = self .auth ,
321323 )
0 commit comments