Skip to content

Commit cd9fde3

Browse files
authored
pack: add $namespaces to the (efffective) root only (#1506)
As per schema-salad v1.x, $namespaces are only valid in the root document: https://www.commonwl.org/v1.0/SchemaSalad.html#Explicit_context https://www.commonwl.org/v1.1/SchemaSalad.html#Explicit_context (same as v1.0) https://www.commonwl.org/v1.2/SchemaSalad.html#Explicit_context (same as v1.0, v1.1) Inspired by (and partial fix for) common-workflow-language/cwl-utils#71 (comment)
1 parent 5a1488b commit cd9fde3

File tree

6 files changed

+33
-28
lines changed

6 files changed

+33
-28
lines changed

cwltool/pack.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ def rewrite_id(r: str, mainuri: str) -> None:
268268

269269
if schemas:
270270
packed["$schemas"] = list(schemas)
271+
if namespaces:
272+
packed["$namespaces"] = namespaces
271273

272274
for r in list(rewrite.keys()):
273275
v = rewrite[r]
@@ -276,14 +278,13 @@ def rewrite_id(r: str, mainuri: str) -> None:
276278
import_embed(packed, set())
277279

278280
if len(packed["$graph"]) == 1:
279-
# duplicate 'cwlVersion' and $schemas inside $graph when there is only
280-
# a single item because we will print the contents inside '$graph'
281-
# rather than whole dict
281+
# duplicate 'cwlVersion', '$schemas', and '$namespaces' inside '$graph'
282+
# when there is only a single item because main.print_pack() will print
283+
# the contents inside '$graph' rather than whole dict in this case
282284
packed["$graph"][0]["cwlVersion"] = packed["cwlVersion"]
283285
if schemas:
284286
packed["$graph"][0]["$schemas"] = list(schemas)
285-
# always include $namespaces in the #main
286-
if namespaces:
287-
packed["$graph"][0]["$namespaces"] = namespaces
287+
if namespaces:
288+
packed["$graph"][0]["$namespaces"] = namespaces
288289

289290
return packed

tests/test_pack.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ def test_pack_fragment() -> None:
9494
)
9595
adjustDirObjs(packed, partial(make_relative, os.path.abspath(get_data("tests/wf"))))
9696

97-
assert json.dumps(packed, sort_keys=True, indent=2) == json.dumps(
98-
expect_packed, sort_keys=True, indent=2
99-
)
97+
packed_result = json.dumps(packed, sort_keys=True, indent=2)
98+
expected = json.dumps(expect_packed, sort_keys=True, indent=2)
99+
100+
assert packed_result == expected
100101

101102

102103
def test_pack_rewrites() -> None:

tests/wf/expect_packed.cwl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@
6767
"id": "#main/sorted"
6868
}
6969
],
70-
"id": "#main",
71-
"$namespaces": {
72-
"iana": "https://www.iana.org/assignments/media-types/"
73-
}
70+
"id": "#main"
7471
},
7572
{
7673
"class": "CommandLineTool",
@@ -133,5 +130,8 @@
133130
"$schemas": [
134131
"empty.ttl",
135132
"empty2.ttl"
136-
]
133+
],
134+
"$namespaces": {
135+
"iana": "https://www.iana.org/assignments/media-types/"
136+
}
137137
}

tests/wf/expect_revsort_datetime_packed.cwl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@
6868
}
6969
],
7070
"id": "#main",
71-
"http://schema.org/dateCreated": "2020-10-08",
72-
"$namespaces": {
73-
"iana": "https://www.iana.org/assignments/media-types/",
74-
"s": "http://schema.org/"
75-
}
71+
"http://schema.org/dateCreated": "2020-10-08"
7672
},
7773
{
7874
"class": "CommandLineTool",
@@ -136,5 +132,9 @@
136132
"empty2.ttl",
137133
"https://schema.org/version/latest/schemaorg-current-https.rdf",
138134
"empty.ttl"
139-
]
140-
}
135+
],
136+
"$namespaces": {
137+
"iana": "https://www.iana.org/assignments/media-types/",
138+
"s": "http://schema.org/"
139+
}
140+
}

tests/wf/expect_trick_packed.cwl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
],
2222
"baseCommand": "rev",
2323
"stdout": "output.txt",
24-
"id": "#revtool.cwl",
25-
"$namespaces": {
26-
"iana": "https://www.iana.org/assignments/media-types/"
27-
}
24+
"id": "#revtool.cwl"
2825
},
2926
{
3027
"class": "CommandLineTool",
@@ -138,5 +135,8 @@
138135
"$schemas": [
139136
"empty2.ttl",
140137
"empty.ttl"
141-
]
142-
}
138+
],
139+
"$namespaces": {
140+
"iana": "https://www.iana.org/assignments/media-types/"
141+
}
142+
}

tests/wf/scatter2_subwf.cwl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,8 @@
7272
]
7373
}
7474
],
75-
"cwlVersion": "v1.0"
75+
"cwlVersion": "v1.0",
76+
"$namespaces": {
77+
"arv": "http://arvados.org/cwl#"
78+
}
7679
}

0 commit comments

Comments
 (0)