Skip to content

Commit 87f475e

Browse files
authored
Merge pull request #1 from common-workflow-language/master
merge new changes
2 parents dd3f90a + 47f4e3f commit 87f475e

File tree

7 files changed

+59
-36
lines changed

7 files changed

+59
-36
lines changed

cwltool/cwlNodeEngine.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
2-
process.stdin.setEncoding('utf8');
2+
process.stdin.setEncoding("utf8");
33
var incoming = "";
4-
process.stdin.on('data', function(chunk) {
4+
process.stdin.on("data", function(chunk) {
55
incoming += chunk;
66
var i = incoming.indexOf("\n");
77
if (i > -1) {
@@ -10,4 +10,4 @@ process.stdin.on('data', function(chunk) {
1010
process.stdout.write(JSON.stringify(require("vm").runInNewContext(fn, {})) + "\n");
1111
}
1212
});
13-
process.stdin.on('end', process.exit);
13+
process.stdin.on("end", process.exit);

cwltool/job.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,22 @@ def run(self, dry_run=False, pull_image=True, rm_container=True,
135135

136136
img_id = None
137137
env = None # type: Union[MutableMapping[Text, Text], MutableMapping[str, str]]
138-
if docker_req and kwargs.get("use_container") is not False:
139-
env = os.environ
140-
img_id = docker.get_from_requirements(docker_req, docker_is_req, pull_image)
141-
elif kwargs.get("default_container", None) is not None:
142-
env = os.environ
143-
img_id = kwargs.get("default_container")
144-
145-
if docker_is_req and img_id is None:
146-
raise WorkflowException("Docker is required for running this tool.")
138+
try:
139+
if docker_req and kwargs.get("use_container") is not False:
140+
env = os.environ
141+
img_id = docker.get_from_requirements(docker_req, True, pull_image)
142+
elif kwargs.get("default_container", None) is not None:
143+
env = os.environ
144+
img_id = kwargs.get("default_container")
145+
146+
if docker_req and img_id is None and kwargs.get("use_container"):
147+
raise Exception("Docker image not available")
148+
except Exception as e:
149+
_logger.debug("Docker error", exc_info=True)
150+
if docker_is_req:
151+
raise WorkflowException("Docker is required to run this tool: %s" % e)
152+
else:
153+
raise WorkflowException("Docker is not available for this tool, try --no-container to disable Docker: %s" % e)
147154

148155
if img_id:
149156
runtime = ["docker", "run", "-i"]

cwltool/sandboxjs.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ def new_js_proc():
3333
trynodes = ("nodejs", "node")
3434
for n in trynodes:
3535
try:
36-
nodejs = subprocess.Popen([n, "--eval", nodecode], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
36+
if subprocess.check_output([n, "--eval", "process.stdout.write('t')"]) != "t":
37+
continue
38+
nodejs = subprocess.Popen([n, "--eval", nodecode],
39+
stdin=subprocess.PIPE,
40+
stdout=subprocess.PIPE,
3741
stderr=subprocess.PIPE)
3842
break
43+
except subprocess.CalledProcessError:
44+
pass
3945
except OSError as e:
4046
if e.errno == errno.ENOENT:
4147
pass
@@ -103,26 +109,28 @@ def term():
103109
stdout_buf = BytesIO()
104110
stderr_buf = BytesIO()
105111

106-
completed = [] # type: List[BytesIO]
107-
while len(completed) < 3:
108-
rready, wready, _ = select.select([nodejs.stdout, nodejs.stderr], [nodejs.stdin], [])
109-
if nodejs.stdin in wready:
110-
b = stdin_buf.read(select.PIPE_BUF)
111-
if b:
112-
os.write(nodejs.stdin.fileno(), b)
113-
elif stdin_buf not in completed:
114-
completed.append(stdin_buf)
115-
for pipes in ((nodejs.stdout, stdout_buf), (nodejs.stderr, stderr_buf)):
116-
if pipes[0] in rready:
117-
b = os.read(pipes[0].fileno(), select.PIPE_BUF)
112+
rselect = [nodejs.stdout, nodejs.stderr] # type: List[BytesIO]
113+
wselect = [nodejs.stdin] # type: List[BytesIO]
114+
while (len(wselect) + len(rselect)) > 0:
115+
rready, wready, _ = select.select(rselect, wselect, [])
116+
try:
117+
if nodejs.stdin in wready:
118+
b = stdin_buf.read(select.PIPE_BUF)
118119
if b:
119-
pipes[1].write(b)
120-
elif pipes[1] not in completed:
121-
completed.append(pipes[1])
122-
if stdout_buf.getvalue().endswith("\n"):
123-
for buf in (stdout_buf, stderr_buf):
124-
if buf not in completed:
125-
completed.append(buf)
120+
os.write(nodejs.stdin.fileno(), b)
121+
else:
122+
wselect = []
123+
for pipes in ((nodejs.stdout, stdout_buf), (nodejs.stderr, stderr_buf)):
124+
if pipes[0] in rready:
125+
b = os.read(pipes[0].fileno(), select.PIPE_BUF)
126+
if b:
127+
pipes[1].write(b)
128+
else:
129+
rselect.remove(pipes[0])
130+
if stdout_buf.getvalue().endswith("\n"):
131+
rselect = []
132+
except OSError as e:
133+
break
126134
tm.cancel()
127135

128136
stdin_buf.close()
@@ -143,6 +151,8 @@ def stdfmt(data): # type: (unicode) -> unicode
143151
return "\n" + data.strip()
144152
return data
145153

154+
nodejs.poll()
155+
146156
if debug:
147157
info = u"returncode was: %s\nscript was:\n%s\nstdout was: %s\nstderr was: %s\n" %\
148158
(nodejs.returncode, fn_linenum(), stdfmt(stdoutdata), stdfmt(stderrdata))

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ ruamel.yaml==0.13.7
33
rdflib==4.2.1
44
rdflib-jsonld==0.4.0
55
shellescape==3.4.1
6-
schema-salad>=2.1.20170208112505,<3
6+
schema-salad>=2.3.20170302225134,<3
77
typing==3.5.2.2 ; python_version>="2.7"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'ruamel.yaml >= 0.12.4',
5151
'rdflib >= 4.2.2, < 4.3.0',
5252
'shellescape >= 3.4.1, < 3.5',
53-
'schema-salad >= 2.2.20170222151604, < 3',
53+
'schema-salad >= 2.3.20170302225134, < 3',
5454
'typing >= 3.5.2, < 3.6',
5555
'six >= 1.10.0',
5656

tests/test_examples.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cwltool.process
77
import cwltool.workflow
88
from .util import get_data
9+
from cwltool.main import main
910

1011
class TestParamMatching(unittest.TestCase):
1112
def test_params(self):
@@ -336,6 +337,11 @@ def test_lifting(self):
336337
echo = f.make(get_data("tests/test_bad_outputs_wf.cwl"))
337338
self.assertEqual(echo(inp="foo"), {"out": "foo\n"})
338339

340+
class TestPrintDot(unittest.TestCase):
341+
def test_print_dot(self):
342+
# Require that --enable-ext is provided.
343+
self.assertEquals(main(["--print-dot", get_data('tests/wf/revsort.cwl')]), 0)
344+
339345

340346
if __name__ == '__main__':
341347
unittest.main()

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ deps = -rrequirements.txt
1515
commands = make mypy
1616
whitelist_externals = make
1717
deps =
18-
mypy>=0.470
18+
mypy==0.470
1919
typed-ast==0.6.3
2020
-rrequirements.txt
2121

2222
[testenv:py35-mypy]
2323
commands = make mypy3
2424
whitelist_externals = make
2525
deps =
26-
mypy>=0.470
26+
mypy==0.470
2727
typed-ast==0.6.3
2828
-rrequirements.txt
2929

0 commit comments

Comments
 (0)