Skip to content

Preserve namespaces after packing #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cwltool/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def rewrite_id(r, mainuri):

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

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

return packed
33 changes: 30 additions & 3 deletions tests/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
from functools import partial
import tempfile

import pytest
from six import StringIO
Expand Down Expand Up @@ -47,7 +48,7 @@ def test_pack_missing_cwlVersion(self):
# Testing single tool workflow
document_loader, workflowobj, uri = fetch_document(
get_data("tests/wf/hello_single_tool.cwl"))
document_loader, avsc_names, processobj, metadata, uri = validate_document(
document_loader, _, processobj, metadata, uri = validate_document(
document_loader, workflowobj, uri)
# generate pack output dict
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
Expand All @@ -57,7 +58,7 @@ def test_pack_missing_cwlVersion(self):
# Testing single step workflow
document_loader, workflowobj, uri = fetch_document(
get_data("tests/wf/hello-workflow.cwl"))
document_loader, avsc_names, processobj, metadata, uri = validate_document(
document_loader, _, processobj, metadata, uri = validate_document(
document_loader, workflowobj, uri)
# generate pack output dict
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
Expand Down Expand Up @@ -103,7 +104,7 @@ def test_packed_workflow_execution(self):
document_loader, avsc_names, processobj, metadata, uri = validate_document(
document_loader, workflowobj, uri)
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
temp_packed_path = "/tmp/packedwf"
temp_packed_path = tempfile.mkstemp()[1]
with open(temp_packed_path, 'w') as f:
json.dump(packed, f)
normal_output = StringIO()
Expand All @@ -115,4 +116,30 @@ def test_packed_workflow_execution(self):
get_data(test_wf_job)],
stdout=normal_output), 0)
self.assertEquals(json.loads(packed_output.getvalue()), json.loads(normal_output.getvalue()))
os.remove(temp_packed_path)

@pytest.mark.skipif(onWindows(),
reason="Instance of cwltool is used, on Windows it invokes a default docker container"
"which is not supported on AppVeyor")
def test_preserving_namespaces(self):
test_wf = "tests/wf/formattest.cwl"
test_wf_job = "tests/wf/formattest-job.json"
document_loader, workflowobj, uri = fetch_document(
get_data(test_wf))
document_loader, avsc_names, processobj, metadata, uri = validate_document(
document_loader, workflowobj, uri)
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
assert "$namespaces" in packed
temp_packed_path = tempfile.mkstemp()[1]
with open(temp_packed_path, 'w') as f:
json.dump(packed, f)
normal_output = StringIO()
packed_output = StringIO()
self.assertEquals(main(['--debug', get_data(temp_packed_path),
get_data(test_wf_job)],
stdout=packed_output), 0)
self.assertEquals(main([get_data(test_wf),
get_data(test_wf_job)],
stdout=normal_output), 0)
self.assertEquals(json.loads(packed_output.getvalue()), json.loads(normal_output.getvalue()))
os.remove(temp_packed_path)
7 changes: 7 additions & 0 deletions tests/wf/formattest-job.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"input": {
"class": "File",
"location": "whale.txt",
"format": "edam:format_2330"
}
}
20 changes: 20 additions & 0 deletions tests/wf/formattest.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$namespaces:
edam: "http://edamontology.org/"
cwlVersion: v1.0
class: CommandLineTool
doc: "Reverse each line using the `rev` command"
inputs:
input:
type: File
inputBinding: {}
format: edam:format_2330

outputs:
output:
type: File
outputBinding:
glob: output.txt
format: edam:format_2330

baseCommand: rev
stdout: output.txt