Skip to content

Commit 2212846

Browse files
authored
Merge pull request #586 from common-workflow-language/fix/#584
Preserve namespaces after packing
2 parents 5adb3fb + 696c8ae commit 2212846

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

cwltool/pack.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def rewrite_id(r, mainuri):
149149

150150
packed = {"$graph": [], "cwlVersion": metadata["cwlVersion"]
151151
} # type: Dict[Text, Any]
152+
namespaces = metadata.get('$namespaces', None)
152153

153154
schemas = set() # type: Set[Text]
154155
for r in sorted(runs):
@@ -185,5 +186,7 @@ def rewrite_id(r, mainuri):
185186
# duplicate 'cwlVersion' inside $graph when there is a single item
186187
# because we're printing contents inside '$graph' rather than whole dict
187188
packed["$graph"][0]["cwlVersion"] = packed["cwlVersion"]
189+
if namespaces:
190+
packed["$graph"][0]["$namespaces"] = dict(cast(Dict, namespaces))
188191

189192
return packed

tests/test_pack.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os
77
from functools import partial
8+
import tempfile
89

910
import pytest
1011
from six import StringIO
@@ -47,7 +48,7 @@ def test_pack_missing_cwlVersion(self):
4748
# Testing single tool workflow
4849
document_loader, workflowobj, uri = fetch_document(
4950
get_data("tests/wf/hello_single_tool.cwl"))
50-
document_loader, avsc_names, processobj, metadata, uri = validate_document(
51+
document_loader, _, processobj, metadata, uri = validate_document(
5152
document_loader, workflowobj, uri)
5253
# generate pack output dict
5354
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
@@ -57,7 +58,7 @@ def test_pack_missing_cwlVersion(self):
5758
# Testing single step workflow
5859
document_loader, workflowobj, uri = fetch_document(
5960
get_data("tests/wf/hello-workflow.cwl"))
60-
document_loader, avsc_names, processobj, metadata, uri = validate_document(
61+
document_loader, _, processobj, metadata, uri = validate_document(
6162
document_loader, workflowobj, uri)
6263
# generate pack output dict
6364
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
@@ -103,7 +104,7 @@ def test_packed_workflow_execution(self):
103104
document_loader, avsc_names, processobj, metadata, uri = validate_document(
104105
document_loader, workflowobj, uri)
105106
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
106-
temp_packed_path = "/tmp/packedwf"
107+
temp_packed_path = tempfile.mkstemp()[1]
107108
with open(temp_packed_path, 'w') as f:
108109
json.dump(packed, f)
109110
normal_output = StringIO()
@@ -115,4 +116,30 @@ def test_packed_workflow_execution(self):
115116
get_data(test_wf_job)],
116117
stdout=normal_output), 0)
117118
self.assertEquals(json.loads(packed_output.getvalue()), json.loads(normal_output.getvalue()))
119+
os.remove(temp_packed_path)
118120

121+
@pytest.mark.skipif(onWindows(),
122+
reason="Instance of cwltool is used, on Windows it invokes a default docker container"
123+
"which is not supported on AppVeyor")
124+
def test_preserving_namespaces(self):
125+
test_wf = "tests/wf/formattest.cwl"
126+
test_wf_job = "tests/wf/formattest-job.json"
127+
document_loader, workflowobj, uri = fetch_document(
128+
get_data(test_wf))
129+
document_loader, avsc_names, processobj, metadata, uri = validate_document(
130+
document_loader, workflowobj, uri)
131+
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
132+
assert "$namespaces" in packed
133+
temp_packed_path = tempfile.mkstemp()[1]
134+
with open(temp_packed_path, 'w') as f:
135+
json.dump(packed, f)
136+
normal_output = StringIO()
137+
packed_output = StringIO()
138+
self.assertEquals(main(['--debug', get_data(temp_packed_path),
139+
get_data(test_wf_job)],
140+
stdout=packed_output), 0)
141+
self.assertEquals(main([get_data(test_wf),
142+
get_data(test_wf_job)],
143+
stdout=normal_output), 0)
144+
self.assertEquals(json.loads(packed_output.getvalue()), json.loads(normal_output.getvalue()))
145+
os.remove(temp_packed_path)

tests/wf/formattest-job.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"input": {
3+
"class": "File",
4+
"location": "whale.txt",
5+
"format": "edam:format_2330"
6+
}
7+
}

tests/wf/formattest.cwl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$namespaces:
2+
edam: "http://edamontology.org/"
3+
cwlVersion: v1.0
4+
class: CommandLineTool
5+
doc: "Reverse each line using the `rev` command"
6+
inputs:
7+
input:
8+
type: File
9+
inputBinding: {}
10+
format: edam:format_2330
11+
12+
outputs:
13+
output:
14+
type: File
15+
outputBinding:
16+
glob: output.txt
17+
format: edam:format_2330
18+
19+
baseCommand: rev
20+
stdout: output.txt

0 commit comments

Comments
 (0)