Skip to content

Commit 227f35a

Browse files
authored
Merge pull request #1239 from common-workflow-language/issues/1238_fix_pack
pack: allow inputs/outputs named "name"
2 parents c6cced7 + 5f6d298 commit 227f35a

File tree

4 files changed

+257
-8
lines changed

4 files changed

+257
-8
lines changed

cwltool/pack.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,15 @@ def import_embed(d, seen):
105105
elif isinstance(d, MutableMapping):
106106
for n in ("id", "name"):
107107
if n in d:
108-
if d[n] in seen:
109-
this = d[n]
110-
d.clear()
111-
d["$import"] = this
112-
else:
113-
this = d[n]
114-
seen.add(this)
115-
break
108+
if isinstance(d[n], str):
109+
if d[n] in seen:
110+
this = d[n]
111+
d.clear()
112+
d["$import"] = this
113+
else:
114+
this = d[n]
115+
seen.add(this)
116+
break
116117

117118
for k in sorted(d.keys()):
118119
import_embed(d[k], seen)

tests/test_pack.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,33 @@ def test_pack():
4646
assert packed == expect_packed
4747

4848

49+
def test_pack_input_named_name():
50+
loadingContext, workflowobj, uri = fetch_document(get_data("tests/wf/trick_revsort.cwl"))
51+
loadingContext.do_update = False
52+
loadingContext, uri = resolve_and_validate_document(
53+
loadingContext, workflowobj, uri
54+
)
55+
processobj = loadingContext.loader.resolve_ref(uri)[0]
56+
57+
with open(get_data("tests/wf/expect_trick_packed.cwl")) as packed_file:
58+
expect_packed = yaml.round_trip_load(packed_file)
59+
60+
packed = cwltool.pack.pack(
61+
loadingContext.loader, processobj, uri, loadingContext.metadata
62+
)
63+
adjustFileObjs(
64+
packed, partial(make_relative, os.path.abspath(get_data("tests/wf")))
65+
)
66+
adjustDirObjs(packed, partial(make_relative, os.path.abspath(get_data("tests/wf"))))
67+
68+
assert "$schemas" in packed
69+
assert len(packed["$schemas"]) == len(expect_packed["$schemas"])
70+
del packed["$schemas"]
71+
del expect_packed["$schemas"]
72+
73+
assert packed == expect_packed
74+
75+
4976
def test_pack_single_tool():
5077
loadingContext, workflowobj, uri = fetch_document(
5178
get_data("tests/wf/formattest.cwl")

tests/wf/expect_trick_packed.cwl

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"$graph": [
3+
{
4+
"class": "CommandLineTool",
5+
"doc": "Reverse each line using the `rev` command",
6+
"inputs": [
7+
{
8+
"type": "File",
9+
"inputBinding": {},
10+
"id": "#revtool.cwl/revtool_input"
11+
}
12+
],
13+
"outputs": [
14+
{
15+
"type": "File",
16+
"outputBinding": {
17+
"glob": "output.txt"
18+
},
19+
"id": "#revtool.cwl/revtool_output"
20+
}
21+
],
22+
"baseCommand": "rev",
23+
"stdout": "output.txt",
24+
"id": "#revtool.cwl",
25+
"$namespaces": {
26+
"iana": "https://www.iana.org/assignments/media-types/"
27+
}
28+
},
29+
{
30+
"class": "CommandLineTool",
31+
"doc": "Sort lines using the `sort` command",
32+
"inputs": [
33+
{
34+
"id": "#sorttool.cwl/reverse",
35+
"type": "boolean",
36+
"inputBinding": {
37+
"position": 1,
38+
"prefix": "--reverse"
39+
}
40+
},
41+
{
42+
"id": "#sorttool.cwl/sorted_input",
43+
"type": "File",
44+
"inputBinding": {
45+
"position": 2
46+
}
47+
}
48+
],
49+
"outputs": [
50+
{
51+
"id": "#sorttool.cwl/sorted_output",
52+
"type": "File",
53+
"outputBinding": {
54+
"glob": "output.txt"
55+
}
56+
}
57+
],
58+
"baseCommand": "sort",
59+
"stdout": "output.txt",
60+
"id": "#sorttool.cwl"
61+
},
62+
{
63+
"class": "Workflow",
64+
"doc": "Reverse the lines in a document, then sort those lines.",
65+
"hints": [
66+
{
67+
"class": "DockerRequirement",
68+
"dockerPull": "debian:8"
69+
}
70+
],
71+
"inputs": [
72+
{
73+
"type": "string",
74+
"doc": "Here to test for a bug in --pack",
75+
"id": "#main/name"
76+
},
77+
{
78+
"type": "boolean",
79+
"default": true,
80+
"doc": "If true, reverse (decending) sort",
81+
"id": "#main/reverse_sort"
82+
},
83+
{
84+
"type": "File",
85+
"doc": "The input file to be processed.",
86+
"format": "https://www.iana.org/assignments/media-types/text/plain",
87+
"default": {
88+
"class": "File",
89+
"location": "hello.txt"
90+
},
91+
"id": "#main/workflow_input"
92+
}
93+
],
94+
"outputs": [
95+
{
96+
"type": "File",
97+
"outputSource": "#main/sorted/sorted_output",
98+
"doc": "The output with the lines reversed and sorted.",
99+
"id": "#main/sorted_output"
100+
}
101+
],
102+
"steps": [
103+
{
104+
"in": [
105+
{
106+
"source": "#main/workflow_input",
107+
"id": "#main/rev/revtool_input"
108+
}
109+
],
110+
"out": [
111+
"#main/rev/revtool_output"
112+
],
113+
"run": "#revtool.cwl",
114+
"id": "#main/rev"
115+
},
116+
{
117+
"in": [
118+
{
119+
"source": "#main/reverse_sort",
120+
"id": "#main/sorted/reverse"
121+
},
122+
{
123+
"source": "#main/rev/revtool_output",
124+
"id": "#main/sorted/sorted_input"
125+
}
126+
],
127+
"out": [
128+
"#main/sorted/sorted_output"
129+
],
130+
"run": "#sorttool.cwl",
131+
"id": "#main/sorted"
132+
}
133+
],
134+
"id": "#main"
135+
}
136+
],
137+
"cwlVersion": "v1.0",
138+
"$schemas": [
139+
"empty2.ttl",
140+
"empty.ttl"
141+
]
142+
}

tests/wf/trick_revsort.cwl

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env cwl-runner
2+
#
3+
# This is a two-step workflow which uses "revtool" and "sorttool" defined above.
4+
#
5+
class: Workflow
6+
doc: "Reverse the lines in a document, then sort those lines."
7+
cwlVersion: v1.0
8+
9+
# Requirements & hints specify prerequisites and extensions to the workflow.
10+
# In this example, DockerRequirement specifies a default Docker container
11+
# in which the command line tools will execute.
12+
hints:
13+
- class: DockerRequirement
14+
dockerPull: debian:8
15+
16+
17+
# The inputs array defines the structure of the input object that describes
18+
# the inputs to the workflow.
19+
#
20+
# The "reverse_sort" input parameter demonstrates the "default" field. If the
21+
# field "reverse_sort" is not provided in the input object, the default value will
22+
# be used.
23+
inputs:
24+
workflow_input:
25+
type: File
26+
doc: "The input file to be processed."
27+
format: iana:text/plain
28+
default:
29+
class: File
30+
location: hello.txt
31+
reverse_sort:
32+
type: boolean
33+
default: true
34+
doc: "If true, reverse (decending) sort"
35+
name:
36+
type: string
37+
doc: "Here to test for a bug in --pack"
38+
39+
# The "outputs" array defines the structure of the output object that describes
40+
# the outputs of the workflow.
41+
#
42+
# Each output field must be connected to the output of one of the workflow
43+
# steps using the "outputSource" field. Here, the parameter "sorted_output" of the
44+
# workflow comes from the "sorted_output" output of the "sorted" step.
45+
outputs:
46+
sorted_output:
47+
type: File
48+
outputSource: sorted/sorted_output
49+
doc: "The output with the lines reversed and sorted."
50+
51+
# The "steps" array lists the executable steps that make up the workflow.
52+
# The tool to execute each step is listed in the "run" field.
53+
#
54+
# In the first step, the "in" field of the step connects the upstream
55+
# parameter "workflow_input" of the workflow to the input parameter of the tool
56+
# "revtool_input"
57+
#
58+
# In the second step, the "in" field of the step connects the output
59+
# parameter "revtool_output" from the first step to the input parameter of the
60+
# tool "sorted_input".
61+
steps:
62+
rev:
63+
in:
64+
revtool_input: workflow_input
65+
out: [revtool_output]
66+
run: revtool.cwl
67+
68+
sorted:
69+
in:
70+
sorted_input: rev/revtool_output
71+
reverse: reverse_sort
72+
out: [sorted_output]
73+
run: sorttool.cwl
74+
75+
$namespaces:
76+
iana: https://www.iana.org/assignments/media-types/
77+
78+
$schemas:
79+
- empty2.ttl

0 commit comments

Comments
 (0)