Skip to content

Commit b560933

Browse files
authored
Merge pull request #97 from common-workflow-language/stderr_out_shortcut
initial stderr & stdout shortcut implementation
2 parents 9409dbd + 326ad09 commit b560933

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+688
-256
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: 27 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,30 @@ 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 ('class' in workflowobj
50+
and workflowobj['class'] == 'CommandLineTool'
51+
and 'outputs' in workflowobj):
52+
for out in workflowobj['outputs']:
53+
for streamtype in ['stdout', 'stderr']:
54+
if out['type'] == streamtype:
55+
if 'outputBinding' in out:
56+
raise validate.ValidateException(
57+
"Not allowed to specify outputBinding when"
58+
" using %s shortcut." % streamtype)
59+
if streamtype in workflowobj:
60+
filename = workflowobj[streamtype]
61+
else:
62+
filename = unicode(uuid.uuid4())
63+
workflowobj[streamtype] = filename
64+
out['type'] = 'File'
65+
out['outputBinding'] = {'glob': filename}
66+
else:
67+
for entry in workflowobj:
68+
_convert_stdstreams_to_files(entry)
4469

4570
def validate_document(document_loader, workflowobj, uri,
4671
enable_dev=False, strict=True, preprocess_only=False):
@@ -94,6 +119,8 @@ def validate_document(document_loader, workflowobj, uri,
94119
"$schemas": processobj.get("$schemas", []),
95120
"cwlVersion": processobj["cwlVersion"]}
96121

122+
_convert_stdstreams_to_files(workflowobj)
123+
97124
if preprocess_only:
98125
return document_loader, avsc_names, processobj, metadata, uri
99126

cwltool/schemas/draft-2/conformance_test_draft-2.yaml

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,52 @@
1-
- args: [bwa, mem, -t, '4', -I, '1,2,3,4', -m, '3', draft-2/rabix/tests/test-files/chr20.fa,
2-
draft-2/rabix/tests/test-files/example_human_Illumina.pe_1.fastq, draft-2/rabix/tests/test-files/example_human_Illumina.pe_2.fastq]
1+
- args:
32
job: draft-2/bwa-mem-job.json
4-
stdout: output.sam
53
tool: draft-2/bwa-mem-tool.cwl
4+
output:
5+
args: [bwa, mem, -t, '4', -I, '1,2,3,4', -m, '3',
6+
chr20.fa,
7+
example_human_Illumina.pe_1.fastq,
8+
example_human_Illumina.pe_2.fastq]
69
doc: General test of command line generation
710

8-
- args: [bwa, mem, draft-2/rabix/tests/test-files/chr20.fa,
9-
"-XXX",
10-
"-YYY", draft-2/rabix/tests/test-files/example_human_Illumina.pe_1.fastq,
11-
"-YYY", draft-2/rabix/tests/test-files/example_human_Illumina.pe_2.fastq]
11+
- output:
12+
args: [bwa, mem, chr20.fa,
13+
"-XXX",
14+
"-YYY", example_human_Illumina.pe_1.fastq,
15+
"-YYY", example_human_Illumina.pe_2.fastq]
1216
job: draft-2/bwa-mem-job.json
1317
tool: draft-2/binding-test.cwl
1418
doc: Test nested prefixes with arrays
1519

16-
- args: [tmap, mapall, stage1, map1, --min-seq-length, '20', map2, --min-seq-length,
20+
- output:
21+
args: [tmap, mapall, stage1, map1, --min-seq-length, '20', map2, --min-seq-length,
1722
'20', stage2, map1, --max-seq-length, '20', --min-seq-length, '10', --seed-length,
1823
'16', map2, --max-seed-hits, '-1', --max-seq-length, '20', --min-seq-length, '10']
1924
job: draft-2/tmap-job.json
20-
stdin: draft-2/reads.fastq
21-
stdout: output.sam
2225
tool: draft-2/tmap-tool.cwl
23-
doc: Test nested command line bindings and stdin/stdout redirection
26+
doc: Test nested command line bindings
2427

25-
- args: [cat, draft-2/hello.txt]
28+
- output:
29+
args: [cat, hello.txt]
2630
job: draft-2/cat-job.json
27-
tool: draft-2/cat1-tool.cwl
31+
tool: draft-2/cat1-testcli.cwl
2832
doc: Test command line with optional input (missing)
2933

30-
- args: [cat, -n, draft-2/hello.txt]
34+
- output:
35+
args: [cat, -n, hello.txt]
3136
job: draft-2/cat-n-job.json
32-
tool: draft-2/cat1-tool.cwl
37+
tool: draft-2/cat1-testcli.cwl
3338
doc: Test command line with optional input (provided)
3439

35-
- args: [cat]
36-
job: draft-2/cat-job.json
37-
stdin: draft-2/hello.txt
38-
tool: draft-2/cat2-tool.cwl
39-
doc: Test command line with stdin redirection
40-
41-
- args: [cat, draft-2/hello.txt]
42-
job: draft-2/cat-job.json
43-
stdout: output.txt
44-
tool: draft-2/cat3-tool.cwl
45-
doc: Test command line with stdout redirection
46-
47-
- args: [cat]
48-
job: draft-2/cat-job.json
49-
stdin: draft-2/hello.txt
50-
stdout: output.txt
51-
tool: draft-2/cat4-tool.cwl
52-
doc: Test command line with stdin and stdout redirection
53-
54-
- args: [cat, foo.txt]
55-
createfiles: {foo.txt: 'The file is draft-2/hello.txt
56-
57-
'}
40+
- output:
41+
"foo": {
42+
"checksum": "sha1$63da67422622fbf9251a046d7a34b7ea0fd4fead",
43+
"class": "File",
44+
"path": "foo.txt",
45+
"size": 22
46+
}
5847
job: draft-2/cat-job.json
5948
tool: draft-2/template-tool.cwl
60-
doc: Test CreateFileRequirement ExpressionEngineRequirement.engineConfig features
49+
doc: Test CreateFileRequirement ExpressionEngineRequirement.engineConfig feature
6150

6251
- job: draft-2/cat-job.json
6352
output:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import json
4+
import os
5+
args = [os.path.basename(a) for a in sys.argv[1:]]
6+
with open("cwl.output.json", "w") as f:
7+
json.dump({"args": args}, f)

cwltool/schemas/draft-2/draft-2/binding-test.cwl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ inputs:
1414
inputBinding: { prefix: "-YYY" }
1515
inputBinding: { position: 3, prefix: "-XXX" }
1616

17+
- id: "#args.py"
18+
type: File
19+
default:
20+
class: File
21+
path: args.py
22+
inputBinding:
23+
position: -1
24+
1725
outputs: []
1826

19-
baseCommand: ["bwa", "mem"]
27+
baseCommand: python
28+
arguments: ["bwa", "mem"]

cwltool/schemas/draft-2/draft-2/bwa-mem-job.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"reference": {
33
"class": "File",
4-
"path": "rabix/tests/test-files/chr20.fa",
4+
"path": "chr20.fa",
55
"size": 123,
66
"checksum": "sha1$hash"
77
},
88
"reads": [
99
{
1010
"class": "File",
11-
"path": "rabix/tests/test-files/example_human_Illumina.pe_1.fastq"
11+
"path": "example_human_Illumina.pe_1.fastq"
1212
},
1313
{
1414
"class": "File",
15-
"path": "rabix/tests/test-files/example_human_Illumina.pe_2.fastq"
15+
"path": "example_human_Illumina.pe_2.fastq"
1616
}
1717
],
1818
"min_std_max_min": [

cwltool/schemas/draft-2/draft-2/bwa-mem-tool.cwl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ class: CommandLineTool
44
requirements:
55
- import: node-engine.cwl
66

7-
hints:
8-
- class: DockerRequirement
9-
dockerPull: images.sbgenomics.com/rabix/bwa
10-
dockerImageId: 9d3b9b0359cf
11-
127
inputs:
138
- id: "#reference"
149
type: File
@@ -31,14 +26,28 @@ inputs:
3126
prefix: "-I"
3227
itemSeparator: ","
3328

29+
- id: "#args.py"
30+
type: File
31+
default:
32+
class: File
33+
path: args.py
34+
inputBinding:
35+
position: -1
36+
3437
outputs:
3538
- id: "#sam"
36-
type: "File"
39+
type: ["null", "File"]
3740
outputBinding: { "glob": "output.sam" }
41+
- id: "#args"
42+
type:
43+
type: array
44+
items: string
3845

39-
baseCommand: ["bwa", "mem"]
46+
baseCommand: python
4047

4148
arguments:
49+
- "bwa"
50+
- "mem"
4251
- valueFrom:
4352
engine: "node-engine.cwl"
4453
script: "$job.allocatedResources.cpu"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env cwl-runner
2+
{
3+
"class": "CommandLineTool",
4+
"description": "Print the contents of a file to stdout using 'cat' running in a docker container.",
5+
"inputs": [
6+
{
7+
"id": "#file1",
8+
"type": "File",
9+
"inputBinding": {"position": 1}
10+
},
11+
{
12+
"id": "#numbering",
13+
"type": ["null", "boolean"],
14+
"inputBinding": {
15+
"position": 0,
16+
"prefix": "-n"
17+
}
18+
},
19+
{
20+
id: "#args.py",
21+
type: File,
22+
default: {
23+
class: File,
24+
path: args.py
25+
},
26+
inputBinding: {
27+
position: -1
28+
}
29+
}
30+
],
31+
"outputs": [],
32+
"baseCommand": "python",
33+
"arguments": ["cat"]
34+
}

cwltool/schemas/draft-2/draft-2/cat2-tool.cwl

Lines changed: 0 additions & 23 deletions
This file was deleted.

cwltool/schemas/draft-2/draft-2/chr20.fa

Whitespace-only changes.

cwltool/schemas/draft-2/draft-2/example_human_Illumina.pe_1.fastq

Whitespace-only changes.

cwltool/schemas/draft-2/draft-2/example_human_Illumina.pe_2.fastq

Whitespace-only changes.

cwltool/schemas/draft-2/draft-2/reads.fastq

Whitespace-only changes.

cwltool/schemas/draft-2/draft-2/template-tool.cwl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ requirements:
1717
- filename: foo.txt
1818
fileContent:
1919
engine: "#js"
20-
script: 't("The file is <%= $job.file1.path %>\n")'
20+
script: >
21+
t("The file is <%= $job.file1.path.split('/').slice(-1)[0] %>\n")
2122
inputs:
2223
- id: "#file1"
2324
type: File
24-
outputs: []
25+
outputs:
26+
- id: "#foo"
27+
type: File
28+
outputBinding:
29+
glob: foo.txt
2530
baseCommand: ["cat", "foo.txt"]

0 commit comments

Comments
 (0)