4
4
import json
5
5
import logging
6
6
import os
7
- from subprocess import DEVNULL , CalledProcessError , check_call
7
+ import sys
8
+ from subprocess import DEVNULL , CalledProcessError , check_call # nosec B404
8
9
from typing import Any , Dict , List , Optional , Set , Tuple , Union , cast
9
10
from urllib .request import pathname2url , urlopen
10
11
18
19
def py3_compatible (filePath : str ) -> bool :
19
20
"""Determines if a python file is 3.x compatible by seeing if it compiles in a subprocess"""
20
21
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
22
26
except CalledProcessError as e :
23
27
raise RuntimeError ("Python files must be 3.x compatible" ) from e
24
28
return True
@@ -29,9 +33,7 @@ def get_version(extension: str, workflow_file: str) -> str:
29
33
if extension == "py" and py3_compatible (workflow_file ):
30
34
return "3"
31
35
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" ])
35
37
else : # Must be a wdl file.
36
38
# Borrowed from https://github.com/Sage-Bionetworks/synapse-orchestrator/
37
39
# blob/develop/synorchestrator/util.py#L142
@@ -66,7 +68,7 @@ def wf_info(workflow_path: str) -> Tuple[str, str]:
66
68
"http://"
67
69
):
68
70
# If file not local go fetch it.
69
- html = urlopen (workflow_path ).read ()
71
+ html = urlopen (workflow_path ).read () # nosec B310
70
72
local_loc = os .path .join (os .getcwd (), "fetchedFromRemote." + file_type )
71
73
with open (local_loc , "w" ) as f :
72
74
f .write (html .decode ())
@@ -174,7 +176,7 @@ def build_wes_request(
174
176
attach_f : Any = open (attachment , "rb" )
175
177
relpath = os .path .relpath (attachment , wfbase )
176
178
elif attachment .startswith ("http" ):
177
- attach_f = urlopen (attachment )
179
+ attach_f = urlopen (attachment ) # nosec B310
178
180
relpath = os .path .basename (attach_f )
179
181
180
182
parts .append (("workflow_attachment" , (relpath , attach_f )))
@@ -226,7 +228,7 @@ def get_service_info(self) -> Dict[str, Any]:
226
228
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
227
229
:return: The body of the get result as a dictionary.
228
230
"""
229
- postresult = requests .get (
231
+ postresult = requests .get ( # nosec B113
230
232
f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/service-info" ,
231
233
headers = self .auth ,
232
234
)
@@ -244,7 +246,7 @@ def list_runs(self) -> Dict[str, Any]:
244
246
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
245
247
:return: The body of the get result as a dictionary.
246
248
"""
247
- postresult = requests .get (
249
+ postresult = requests .get ( # nosec B113
248
250
f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs" , headers = self .auth
249
251
)
250
252
return wes_reponse (postresult )
@@ -266,7 +268,7 @@ def run(
266
268
"""
267
269
attachments = list (expand_globs (attachments ))
268
270
parts = build_wes_request (wf , jsonyaml , attachments )
269
- postresult = requests .post (
271
+ postresult = requests .post ( # nosec B113
270
272
f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs" ,
271
273
files = parts ,
272
274
headers = self .auth ,
@@ -283,7 +285,7 @@ def cancel(self, run_id: str) -> Dict[str, Any]:
283
285
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
284
286
:return: The body of the delete result as a dictionary.
285
287
"""
286
- postresult = requests .post (
288
+ postresult = requests .post ( # nosec B113
287
289
f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs/{ run_id } /cancel" ,
288
290
headers = self .auth ,
289
291
)
@@ -299,7 +301,7 @@ def get_run_log(self, run_id: str) -> Dict[str, Any]:
299
301
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
300
302
:return: The body of the get result as a dictionary.
301
303
"""
302
- postresult = requests .get (
304
+ postresult = requests .get ( # nosec B113
303
305
f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs/{ run_id } " ,
304
306
headers = self .auth ,
305
307
)
@@ -315,7 +317,7 @@ def get_run_status(self, run_id: str) -> Dict[str, Any]:
315
317
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
316
318
:return: The body of the get result as a dictionary.
317
319
"""
318
- postresult = requests .get (
320
+ postresult = requests .get ( # nosec B113
319
321
f"{ self .proto } ://{ self .host } /ga4gh/wes/v1/runs/{ run_id } /status" ,
320
322
headers = self .auth ,
321
323
)
0 commit comments