1
1
import os
2
2
import json
3
- import glob
4
- import requests
5
- import urllib
6
- import logging
7
3
import schema_salad .ref_resolver
8
- from wes_service .util import visit
9
4
import subprocess
10
5
import yaml
11
6
import glob
12
7
import requests
13
8
import urllib
14
9
import logging
15
- import schema_salad .ref_resolver
16
10
17
11
from wes_service .util import visit
18
12
from urllib import urlopen
19
13
20
- def _twoSevenCompatible (filePath ):
14
+
15
+ def _two_seven_compatible (filePath ):
21
16
"""Determines if a python file is 2.7 compatible by seeing if it compiles in a subprocess"""
22
17
try :
23
18
passes = not subprocess .call (['python2' , '-m' , 'py_compile' , filePath ])
@@ -26,9 +21,9 @@ def _twoSevenCompatible(filePath):
26
21
return passes
27
22
28
23
29
- def _getVersion (extension , workflow_file ):
24
+ def _get_version (extension , workflow_file ):
30
25
'''Determines the version of a .py, .wdl, or .cwl file.'''
31
- if extension == 'py' and _twoSevenCompatible (workflow_file ):
26
+ if extension == 'py' and _two_seven_compatible (workflow_file ):
32
27
return '2.7'
33
28
elif extension == 'cwl' :
34
29
return yaml .load (open (workflow_file ))['cwlVersion' ]
@@ -49,26 +44,26 @@ def wf_info(workflow_path):
49
44
enable our approach to version checking, then removed after version is extracted.
50
45
"""
51
46
52
- supportedFormats = ['py' , 'wdl' , 'cwl' ]
53
- fileType = workflow_path .lower ().split ('.' )[- 1 ] # Grab the file extension
47
+ supported_formats = ['py' , 'wdl' , 'cwl' ]
48
+ file_type = workflow_path .lower ().split ('.' )[- 1 ] # Grab the file extension
54
49
workflow_path = workflow_path if ':' in workflow_path else 'file://' + workflow_path
55
50
56
- if fileType in supportedFormats :
51
+ if file_type in supported_formats :
57
52
if workflow_path .startswith ('file://' ):
58
- version = _getVersion ( fileType , workflow_path [7 :])
53
+ version = _get_version ( file_type , workflow_path [7 :])
59
54
elif workflow_path .startswith ('https://' ) or workflow_path .startswith ('http://' ):
60
55
# If file not local go fetch it.
61
56
html = urlopen (workflow_path ).read ()
62
- localLoc = os .path .join (os .getcwd (), 'fetchedFromRemote.' + fileType )
63
- with open (localLoc , 'w' ) as f :
57
+ local_loc = os .path .join (os .getcwd (), 'fetchedFromRemote.' + file_type )
58
+ with open (local_loc , 'w' ) as f :
64
59
f .write (html )
65
- version = wf_info ('file://' + localLoc )[0 ] # Don't take the fileType here, found it above.
66
- os .remove (localLoc ) # TODO: Find a way to avoid recreating file before version determination.
60
+ version = wf_info ('file://' + local_loc )[0 ] # Don't take the file_type here, found it above.
61
+ os .remove (local_loc ) # TODO: Find a way to avoid recreating file before version determination.
67
62
else :
68
63
raise NotImplementedError ('Unsupported workflow file location: {}. Must be local or HTTP(S).' .format (workflow_path ))
69
64
else :
70
- raise TypeError ('Unsupported workflow type: .{}. Must be {}.' .format (fileType , '.py, .cwl, or .wdl' ))
71
- return version , fileType .upper ()
65
+ raise TypeError ('Unsupported workflow type: .{}. Must be {}.' .format (file_type , '.py, .cwl, or .wdl' ))
66
+ return version , file_type .upper ()
72
67
73
68
74
69
def build_wes_request (workflow_file , json_path , attachments = None ):
0 commit comments