Skip to content

Commit 5a2f23a

Browse files
committed
support packed $graph documents
1 parent faff174 commit 5a2f23a

File tree

4 files changed

+191
-10
lines changed

4 files changed

+191
-10
lines changed

cwlupgrader/main.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,14 @@ def process_imports(
217217
def v1_0_to_v1_1(document: CommentedMap, outdir: str) -> CommentedMap:
218218
"""CWL v1.0.x to v1.1 transformation loop."""
219219
_v1_0_to_v1_1(document, outdir)
220-
if isinstance(document, MutableMapping):
221-
for key, value in document.items():
222-
with SourceLine(document, key, Exception):
223-
if isinstance(value, CommentedMap):
224-
document[key] = _v1_0_to_v1_1(value, outdir)
225-
elif isinstance(value, list):
226-
for index, entry in enumerate(value):
227-
if isinstance(entry, CommentedMap):
228-
value[index] = _v1_0_to_v1_1(entry, outdir)
220+
for key, value in document.items():
221+
with SourceLine(document, key, Exception):
222+
if isinstance(value, CommentedMap):
223+
document[key] = _v1_0_to_v1_1(value, outdir)
224+
elif isinstance(value, list):
225+
for index, entry in enumerate(value):
226+
if isinstance(entry, CommentedMap):
227+
value[index] = _v1_0_to_v1_1(entry, outdir)
229228
document["cwlVersion"] = "v1.1"
230229
return sort_v1_0(document)
231230

@@ -345,12 +344,17 @@ def _v1_0_to_v1_1(document: CommentedMap, outdir: str) -> CommentedMap:
345344
_v1_0_to_v1_1(process, outdir)
346345
if "cwlVersion" in process:
347346
del process["cwlVersion"]
348-
elif isinstance(entry["run"], str):
347+
elif (
348+
isinstance(entry["run"], str)
349+
and "#" not in entry["run"]
350+
):
349351
path = Path(document.lc.filename).parent / entry["run"]
350352
process = v1_0_to_v1_1(
351353
load_cwl_document(str(path)), outdir
352354
)
353355
write_cwl_document(process, path.name, outdir)
356+
elif isinstance(entry["run"], str) and "#" in entry["run"]:
357+
pass # reference to $graph entry
354358
else:
355359
raise Exception(
356360
"'run' entry was neither a CWL Process nor "

testdata/v1.0/conflict-wf.cwl

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
cwlVersion: v1.0
2+
$graph:
3+
- id: echo
4+
class: CommandLineTool
5+
hints:
6+
ResourceRequirement:
7+
ramMin: 8
8+
inputs:
9+
text:
10+
type: string
11+
inputBinding: {}
12+
13+
outputs:
14+
fileout:
15+
type: File
16+
outputBinding:
17+
glob: out.txt
18+
19+
baseCommand: echo
20+
stdout: out.txt
21+
22+
- id: cat
23+
class: CommandLineTool
24+
hints:
25+
ResourceRequirement:
26+
ramMin: 8
27+
28+
inputs:
29+
file1:
30+
type: File
31+
inputBinding:
32+
position: 1
33+
file2:
34+
type: File
35+
inputBinding:
36+
position: 2
37+
38+
outputs:
39+
fileout:
40+
type: File
41+
outputBinding:
42+
glob: out.txt
43+
44+
baseCommand: cat
45+
stdout: out.txt
46+
47+
- class: Workflow
48+
id: collision
49+
50+
inputs:
51+
input_1: string
52+
input_2: string
53+
54+
outputs:
55+
fileout:
56+
type: File
57+
outputSource: cat_step/fileout
58+
59+
steps:
60+
echo_1:
61+
run: "#echo"
62+
in:
63+
text: input_1
64+
out: [fileout]
65+
66+
echo_2:
67+
run: "#echo"
68+
in:
69+
text: input_2
70+
out: [fileout]
71+
72+
cat_step:
73+
run: "#cat"
74+
in:
75+
file1:
76+
source: echo_1/fileout
77+
file2:
78+
source: echo_2/fileout
79+
out: [fileout]

testdata/v1.1/conflict-wf.cwl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.1
3+
$graph:
4+
- id: echo
5+
class: CommandLineTool
6+
hints:
7+
ResourceRequirement:
8+
ramMin: 8
9+
NetworkAccess:
10+
networkAccess: true
11+
LoadListingRequirement:
12+
loadListing: deep_listing
13+
inputs:
14+
text:
15+
type: string
16+
inputBinding: {}
17+
18+
outputs:
19+
fileout:
20+
type: File
21+
outputBinding:
22+
glob: out.txt
23+
24+
baseCommand: echo
25+
stdout: out.txt
26+
27+
- id: cat
28+
class: CommandLineTool
29+
hints:
30+
ResourceRequirement:
31+
ramMin: 8
32+
33+
NetworkAccess:
34+
networkAccess: true
35+
LoadListingRequirement:
36+
loadListing: deep_listing
37+
inputs:
38+
file1:
39+
type: File
40+
inputBinding:
41+
position: 1
42+
file2:
43+
type: File
44+
inputBinding:
45+
position: 2
46+
47+
outputs:
48+
fileout:
49+
type: File
50+
outputBinding:
51+
glob: out.txt
52+
53+
baseCommand: cat
54+
stdout: out.txt
55+
56+
- class: Workflow
57+
id: collision
58+
59+
inputs:
60+
input_1: string
61+
input_2: string
62+
63+
outputs:
64+
fileout:
65+
type: File
66+
outputSource: cat_step/fileout
67+
68+
steps:
69+
echo_1:
70+
run: "#echo"
71+
in:
72+
text: input_1
73+
out: [fileout]
74+
75+
echo_2:
76+
run: "#echo"
77+
in:
78+
text: input_2
79+
out: [fileout]
80+
81+
cat_step:
82+
run: "#cat"
83+
in:
84+
file1:
85+
source: echo_1/fileout
86+
file2:
87+
source: echo_2/fileout
88+
out: [fileout]

tests/test_complete.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ def test_v1_1_to_v1_2(tmp_path: Path) -> None:
3636
doc = load_cwl_document(get_data("testdata/v1.1/listing_deep1.cwl"))
3737
upgraded = upgrade_document(doc, str(tmp_path), "v1.2")
3838
assert doc == upgraded
39+
40+
41+
def test_packed_graph(tmp_path: Path) -> None:
42+
"""Test packed document with $graph."""
43+
main([f"--dir={tmp_path}", "--v1.1-only", get_data("testdata/v1.0/conflict-wf.cwl")])
44+
assert filecmp.cmp(
45+
get_data("testdata/v1.1/conflict-wf.cwl"),
46+
tmp_path / "conflict-wf.cwl",
47+
shallow=False,
48+
)

0 commit comments

Comments
 (0)