8
8
from io import BytesIO
9
9
10
10
from pkg_resources import resource_stream
11
- from typing import Any , Dict , List , Mapping , Text , Union
11
+ from typing import Any , Dict , List , Mapping , Text , Union , Tuple
12
+
12
13
13
14
class JavascriptException (Exception ):
14
15
pass
@@ -21,6 +22,27 @@ class JavascriptException(Exception):
21
22
localdata = threading .local ()
22
23
23
24
have_node_slim = False
25
+ # minimum acceptable version of nodejs engine
26
+ minimum_node_version_str = '0.10.26'
27
+
28
+ def check_js_threshold_version (working_alias ):
29
+ # type: (str) -> bool
30
+
31
+ """Checks if the nodeJS engine version on the system
32
+ with the allowed minimum version.
33
+ https://github.com/nodejs/node/blob/master/CHANGELOG.md#nodejs-changelog
34
+ """
35
+ # parse nodejs version into int Tuple: 'v4.2.6\n' -> [4, 2, 6]
36
+ current_version_str = subprocess .check_output (
37
+ [working_alias , "-v" ]).decode ('ascii' )
38
+
39
+ current_version = [int (v ) for v in current_version_str .strip ().strip ('v' ).split ('.' )]
40
+ minimum_node_version = [int (v ) for v in minimum_node_version_str .split ('.' )]
41
+
42
+ if current_version >= minimum_node_version :
43
+ return True
44
+ else :
45
+ return False
24
46
25
47
26
48
def new_js_proc ():
@@ -29,17 +51,21 @@ def new_js_proc():
29
51
res = resource_stream (__name__ , 'cwlNodeEngine.js' )
30
52
nodecode = res .read ()
31
53
54
+ required_node_version , docker = (False ,)* 2
32
55
nodejs = None
33
56
trynodes = ("nodejs" , "node" )
34
57
for n in trynodes :
35
58
try :
36
59
if subprocess .check_output ([n , "--eval" , "process.stdout.write('t')" ]) != "t" :
37
60
continue
38
- nodejs = subprocess .Popen ([n , "--eval" , nodecode ],
39
- stdin = subprocess .PIPE ,
40
- stdout = subprocess .PIPE ,
41
- stderr = subprocess .PIPE )
42
- break
61
+ else :
62
+ nodejs = subprocess .Popen ([n , "--eval" , nodecode ],
63
+ stdin = subprocess .PIPE ,
64
+ stdout = subprocess .PIPE ,
65
+ stderr = subprocess .PIPE )
66
+
67
+ required_node_version = check_js_threshold_version (n )
68
+ break
43
69
except subprocess .CalledProcessError :
44
70
pass
45
71
except OSError as e :
@@ -48,7 +74,7 @@ def new_js_proc():
48
74
else :
49
75
raise
50
76
51
- if nodejs is None :
77
+ if nodejs is None or nodejs is not None and required_node_version is False :
52
78
try :
53
79
nodeimg = "node:slim"
54
80
global have_node_slim
@@ -63,6 +89,7 @@ def new_js_proc():
63
89
"--sig-proxy=true" , "--interactive" ,
64
90
"--rm" , nodeimg , "node" , "--eval" , nodecode ],
65
91
stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
92
+ docker = True
66
93
except OSError as e :
67
94
if e .errno == errno .ENOENT :
68
95
pass
@@ -71,12 +98,19 @@ def new_js_proc():
71
98
except subprocess .CalledProcessError :
72
99
pass
73
100
101
+ # docker failed and nodejs not on system
74
102
if nodejs is None :
75
103
raise JavascriptException (
76
104
u"cwltool requires Node.js engine to evaluate Javascript "
77
105
"expressions, but couldn't find it. Tried %s, docker run "
78
106
"node:slim" % u", " .join (trynodes ))
79
107
108
+ # docker failed, but nodejs is installed on system but the version is below the required version
109
+ if docker is False and required_node_version is False :
110
+ raise JavascriptException (
111
+ u'cwltool requires minimum v{} version of Node.js engine.' .format (minimum_node_version_str ),
112
+ u'Try updating: https://docs.npmjs.com/getting-started/installing-node' )
113
+
80
114
return nodejs
81
115
82
116
0 commit comments