Skip to content

Commit 3c89fa6

Browse files
authored
Merge pull request #937 from common-workflow-language/pack_preserve_schema_directive
include top level schemas when packing
2 parents e6dd92a + 03c8a74 commit 3c89fa6

File tree

7 files changed

+96
-60
lines changed

7 files changed

+96
-60
lines changed

cwltool/pack.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ def rewrite_id(r, mainuri):
174174
namespaces = metadata.get('$namespaces', None)
175175

176176
schemas = set() # type: Set[Text]
177+
if '$schemas' in metadata:
178+
for each_schema in metadata["$schemas"]:
179+
schemas.add(each_schema)
177180
for r in sorted(runs):
178181
dcr, metadata = document_loader.resolve_ref(r)
179182
if isinstance(dcr, CommentedSeq):
@@ -205,10 +208,15 @@ def rewrite_id(r, mainuri):
205208
import_embed(packed, set())
206209

207210
if len(packed["$graph"]) == 1:
208-
# duplicate 'cwlVersion' inside $graph when there is a single item
209-
# because we're printing contents inside '$graph' rather than whole dict
211+
# duplicate 'cwlVersion' and $schemas inside $graph when there is only
212+
# a single item because we will print the contents inside '$graph'
213+
# rather than whole dict
210214
packed["$graph"][0]["cwlVersion"] = packed["cwlVersion"]
215+
if schemas:
216+
packed["$graph"][0]["$schemas"] = list(schemas)
217+
# always include $namespaces in the #main
211218
if namespaces:
212219
packed["$graph"][0]["$namespaces"] = dict(cast(Dict, namespaces))
213220

221+
214222
return packed

tests/test_pack.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,24 @@ def test_pack():
3232
adjustDirObjs(packed, partial(make_relative, os.path.abspath(get_data("tests/wf"))))
3333

3434
assert "$schemas" in packed
35-
35+
assert len(packed["$schemas"]) == len(expect_packed["$schemas"])
3636
del packed["$schemas"]
3737
del expect_packed["$schemas"]
3838

3939
assert packed == expect_packed
4040

4141

42+
def test_pack_single_tool():
43+
load_tool.loaders = {}
44+
45+
document_loader, workflowobj, uri = fetch_document(
46+
get_data("tests/wf/formattest.cwl"))
47+
document_loader, _, processobj, metadata, uri = validate_document(
48+
document_loader, workflowobj, uri)
49+
50+
packed = cwltool.pack.pack(document_loader, processobj, uri, metadata)
51+
assert "$schemas" in packed
52+
4253
def test_pack_rewrites():
4354
load_tool.loaders = {}
4455
rewrites = {}

tests/wf/empty2.ttl

Whitespace-only changes.

tests/wf/expect_packed.cwl

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
11
{
2-
"cwlVersion": "v1.0",
3-
"$schemas": ["file:///home/peter/work/cwltool/tests/wf/empty.ttl"],
42
"$graph": [
53
{
4+
"class": "Workflow",
5+
"doc": "Reverse the lines in a document, then sort those lines.",
6+
"hints": [
7+
{
8+
"class": "DockerRequirement",
9+
"dockerPull": "debian:8"
10+
}
11+
],
612
"inputs": [
713
{
8-
"doc": "The input file to be processed.",
914
"type": "File",
10-
"id": "#main/input",
15+
"doc": "The input file to be processed.",
16+
"format": "https://www.iana.org/assignments/media-types/text/plain",
1117
"default": {
12-
"class": "File",
13-
"location": "hello.txt"
14-
}
18+
"class": "File",
19+
"location": "hello.txt"
20+
},
21+
"id": "#main/input"
1522
},
1623
{
24+
"type": "boolean",
1725
"default": true,
1826
"doc": "If true, reverse (decending) sort",
19-
"type": "boolean",
2027
"id": "#main/reverse_sort"
2128
}
2229
],
23-
"doc": "Reverse the lines in a document, then sort those lines.",
24-
"class": "Workflow",
30+
"outputs": [
31+
{
32+
"type": "File",
33+
"outputSource": "#main/sorted/output",
34+
"doc": "The output with the lines reversed and sorted.",
35+
"id": "#main/output"
36+
}
37+
],
2538
"steps": [
2639
{
27-
"out": [
28-
"#main/rev/output"
29-
],
30-
"run": "#revtool.cwl",
31-
"id": "#main/rev",
3240
"in": [
3341
{
3442
"source": "#main/input",
3543
"id": "#main/rev/input"
3644
}
37-
]
38-
},
39-
{
45+
],
4046
"out": [
41-
"#main/sorted/output"
47+
"#main/rev/output"
4248
],
43-
"run": "#sorttool.cwl",
44-
"id": "#main/sorted",
49+
"run": "#revtool.cwl",
50+
"id": "#main/rev"
51+
},
52+
{
4553
"in": [
4654
{
4755
"source": "#main/rev/output",
@@ -51,80 +59,79 @@
5159
"source": "#main/reverse_sort",
5260
"id": "#main/sorted/reverse"
5361
}
54-
]
55-
}
56-
],
57-
"outputs": [
58-
{
59-
"outputSource": "#main/sorted/output",
60-
"type": "File",
61-
"id": "#main/output",
62-
"doc": "The output with the lines reversed and sorted."
62+
],
63+
"out": [
64+
"#main/sorted/output"
65+
],
66+
"run": "#sorttool.cwl",
67+
"id": "#main/sorted"
6368
}
6469
],
6570
"id": "#main",
66-
"hints": [
67-
{
68-
"dockerPull": "debian:8",
69-
"class": "DockerRequirement"
70-
}
71-
]
71+
"$namespaces": {
72+
"iana": "https://www.iana.org/assignments/media-types/"
73+
}
7274
},
7375
{
76+
"class": "CommandLineTool",
77+
"doc": "Reverse each line using the `rev` command",
7478
"inputs": [
7579
{
76-
"inputBinding": {},
7780
"type": "File",
81+
"inputBinding": {},
7882
"id": "#revtool.cwl/input"
7983
}
8084
],
81-
"stdout": "output.txt",
82-
"doc": "Reverse each line using the `rev` command",
83-
"baseCommand": "rev",
84-
"class": "CommandLineTool",
8585
"outputs": [
8686
{
87+
"type": "File",
8788
"outputBinding": {
8889
"glob": "output.txt"
8990
},
90-
"type": "File",
9191
"id": "#revtool.cwl/output"
9292
}
9393
],
94+
"baseCommand": "rev",
95+
"stdout": "output.txt",
9496
"id": "#revtool.cwl"
9597
},
9698
{
99+
"class": "CommandLineTool",
100+
"doc": "Sort lines using the `sort` command",
97101
"inputs": [
98102
{
103+
"id": "#sorttool.cwl/reverse",
104+
"type": "boolean",
99105
"inputBinding": {
100106
"position": 1,
101107
"prefix": "--reverse"
102-
},
103-
"type": "boolean",
104-
"id": "#sorttool.cwl/reverse"
108+
}
105109
},
106110
{
111+
"id": "#sorttool.cwl/input",
112+
"type": "File",
107113
"inputBinding": {
108114
"position": 2
109-
},
110-
"type": "File",
111-
"id": "#sorttool.cwl/input"
115+
}
112116
}
113117
],
114-
"stdout": "output.txt",
115-
"doc": "Sort lines using the `sort` command",
116-
"baseCommand": "sort",
117-
"class": "CommandLineTool",
118118
"outputs": [
119119
{
120+
"id": "#sorttool.cwl/output",
121+
"type": "File",
120122
"outputBinding": {
121123
"glob": "output.txt"
122-
},
123-
"type": "File",
124-
"id": "#sorttool.cwl/output"
124+
}
125125
}
126126
],
127+
"baseCommand": "sort",
128+
"stdout": "output.txt",
127129
"id": "#sorttool.cwl"
128130
}
131+
],
132+
"cwlVersion": "v1.0",
133+
"$schemas": [
134+
"file:///home/mcrusoe/cwltool/tests/wf/empty2.ttl",
135+
"file:///home/mcrusoe/cwltool/tests/wf/empty.ttl"
129136
]
130137
}

tests/wf/formattest.cwl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env cwl-runner
22
$namespaces:
33
edam: "http://edamontology.org/"
4+
$schemas:
5+
- empty.ttl
46
cwlVersion: v1.0
57
class: CommandLineTool
68
doc: "Reverse each line using the `rev` command"
@@ -18,4 +20,4 @@ outputs:
1820
format: edam:format_2330
1921

2022
baseCommand: rev
21-
stdout: output.txt
23+
stdout: output.txt

tests/wf/revsort-job.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"input": {
33
"class": "File",
4-
"location": "whale.txt"
4+
"location": "whale.txt",
5+
"format": "https://www.iana.org/assignments/media-types/text/plain"
56
}
67
}

tests/wf/revsort.cwl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ inputs:
2424
input:
2525
type: File
2626
doc: "The input file to be processed."
27+
format: iana:text/plain
2728
default:
2829
class: File
2930
location: hello.txt
@@ -67,3 +68,9 @@ steps:
6768
reverse: reverse_sort
6869
out: [output]
6970
run: sorttool.cwl
71+
72+
$namespaces:
73+
iana: https://www.iana.org/assignments/media-types/
74+
75+
$schemas:
76+
- empty2.ttl

0 commit comments

Comments
 (0)