Skip to content

Commit c59f2c4

Browse files
committed
initial stderr & stdout shortcut implementation
1 parent 9409dbd commit c59f2c4

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

cwltool/cwltest.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def run_test(args, i, t): # type: (argparse.Namespace, Any, Dict[str,str]) -> i
7272
outdir = tempfile.mkdtemp()
7373
test_command.extend(["--outdir={}".format(outdir),
7474
"--quiet",
75-
t["tool"],
76-
t["job"]])
75+
t["tool"]])
76+
if t["job"] != None:
77+
test_command.extend([t["job"]])
7778
outstr = subprocess.check_output(test_command)
7879
out = {"output": json.loads(outstr)}
7980
else:
@@ -82,8 +83,9 @@ def run_test(args, i, t): # type: (argparse.Namespace, Any, Dict[str,str]) -> i
8283
"--basedir=" + args.basedir,
8384
"--no-container",
8485
"--quiet",
85-
t["tool"],
86-
t["job"]]
86+
t["tool"]]
87+
if t["job"] != None:
88+
test_command.extend([t["job"]])
8789

8890
outstr = subprocess.check_output(test_command)
8991
out = yaml.load(outstr)
@@ -100,12 +102,12 @@ def run_test(args, i, t): # type: (argparse.Namespace, Any, Dict[str,str]) -> i
100102
_logger.error(t.get("doc"))
101103
_logger.error("Returned non-zero")
102104
return 1
103-
except yaml.scanner.ScannerError as e:
105+
except (yaml.scanner.ScannerError, TypeError) as e:
104106
_logger.error(u"""Test failed: %s""", " ".join([pipes.quote(tc) for tc in test_command]))
105107
_logger.error(outstr)
106108
_logger.error(u"Parse error %s", str(e))
107109

108-
pwd = os.path.abspath(os.path.dirname(t["job"]))
110+
# pwd = os.path.abspath(os.path.dirname(t["job"]))
109111
# t["args"] = map(lambda x: x.replace("$PWD", pwd), t["args"])
110112
# if "stdin" in t:
111113
# t["stdin"] = t["stdin"].replace("$PWD", pwd)
@@ -118,7 +120,8 @@ def run_test(args, i, t): # type: (argparse.Namespace, Any, Dict[str,str]) -> i
118120

119121
for key in checkkeys:
120122
try:
121-
compare(t.get(key), out.get(key))
123+
if key in t and key in out:
124+
compare(t.get(key), out.get(key))
122125
except CompareFail as ex:
123126
_logger.warn(u"""Test failed: %s""", " ".join([pipes.quote(tc) for tc in test_command]))
124127
_logger.warn(t.get("doc"))

cwltool/job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def run(self, dry_run=False, pull_image=True, rm_container=True,
154154
" \\\n ".join([shellescape.quote(str(arg)) if shouldquote(str(arg)) else str(arg) for arg in (runtime + self.command_line)]),
155155
u' < %s' % (self.stdin) if self.stdin else '',
156156
u' > %s' % os.path.join(self.outdir, self.stdout) if self.stdout else '',
157-
u' \2> %s' % os.path.join(self.outdir, self.stderr) if self.stderr else '')
157+
u' 2> %s' % os.path.join(self.outdir, self.stderr) if self.stderr else '')
158158

159159
if dry_run:
160160
return (self.outdir, {})

cwltool/load_tool.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""Loads a CWL document."""
33

44
import os
5+
import uuid
56
import logging
67
import re
78
import urlparse
@@ -41,6 +42,24 @@ def fetch_document(argsworkflow):
4142

4243
return document_loader, workflowobj, uri
4344

45+
def _convert_stdstreams_to_files(workflowobj):
46+
# type: (Union[Dict[unicode, Any], List[Dict[unicode, Any]]) -> None
47+
48+
if isinstance(workflowobj, dict):
49+
if 'outputs' in workflowobj:
50+
for out in workflowobj['outputs']:
51+
for streamtype in ['stdout', 'stderr']:
52+
if out['type'] == streamtype:
53+
if streamtype in workflowobj:
54+
filename = workflowobj[streamtype]
55+
else:
56+
filename = unicode(uuid.uuid4())
57+
workflowobj[streamtype] = filename
58+
out['type'] = 'File'
59+
out['outputBinding'] = {'glob': filename}
60+
else:
61+
for entry in workflowobj:
62+
_convert_stdstreams_to_files(entry)
4463

4564
def validate_document(document_loader, workflowobj, uri,
4665
enable_dev=False, strict=True, preprocess_only=False):
@@ -94,6 +113,8 @@ def validate_document(document_loader, workflowobj, uri,
94113
"$schemas": processobj.get("$schemas", []),
95114
"cwlVersion": processobj["cwlVersion"]}
96115

116+
_convert_stdstreams_to_files(workflowobj)
117+
97118
if preprocess_only:
98119
return document_loader, avsc_names, processobj, metadata, uri
99120

0 commit comments

Comments
 (0)