Skip to content

Commit a70a83f

Browse files
authored
Update fragments in index (#1256)
* Fix updater bug referencing a fragment in a packed document
1 parent 4df56e9 commit a70a83f

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

cwltool/load_tool.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from .loghandler import _logger
3535
from .process import Process, get_schema, shortname
3636
from .update import ALLUPDATES
37+
from .utils import visit_class
3738

3839
jobloaderctx = {
3940
"cwl": "https://w3id.org/cwl/cwl#",
@@ -364,6 +365,14 @@ def resolve_and_validate_document(
364365
)
365366
document_loader.idx[processobj["id"]] = processobj
366367

368+
def update_index(pr: CommentedMap) -> None:
369+
if "id" in pr:
370+
document_loader.idx[pr["id"]] = pr
371+
372+
visit_class(
373+
processobj, ("CommandLineTool", "Workflow", "ExpressionTool"), update_index
374+
)
375+
367376
if isinstance(jobobj, CommentedMap):
368377
loadingContext.jobdefaults = jobobj
369378

tests/test_load_tool.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import pytest
2+
import pkg_resources
23

34
from cwltool.context import LoadingContext, RuntimeContext
45
from cwltool.errors import WorkflowException
56
from cwltool.load_tool import load_tool
67
from cwltool.resolver import Path, resolve_local
78
from cwltool.update import INTERNAL_VERSION
9+
from cwltool.process import (
10+
use_custom_schema,
11+
use_standard_schema,
12+
)
813

914
from .test_fetch import norm
1015
from .util import (
@@ -78,5 +83,29 @@ def test_load_graph_fragment():
7883
# of original document and doesn't have cwlVersion set, so test
7984
# that it correctly looks up the root document to get the
8085
# cwlVersion.
81-
tool = load_tool(tool.tool, loadingContext)
86+
tool = load_tool(rs, loadingContext)
8287
assert tool.metadata["cwlVersion"] == INTERNAL_VERSION
88+
89+
90+
def test_load_graph_fragment_from_packed():
91+
"""Loading a fragment from packed with update."""
92+
loadingContext = LoadingContext()
93+
uri = Path(get_data("tests/wf/packed-with-loadlisting.cwl")).as_uri() + "#main"
94+
try:
95+
with open(get_data("cwltool/extensions.yml"), "r") as res:
96+
use_custom_schema("v1.0", "http://commonwl.org/cwltool", res.read())
97+
98+
# The updater transforms LoadListingRequirement from an
99+
# extension (in v1.0) to a core feature (in v1.1) but there
100+
# was a bug when loading a packed workflow and loading a
101+
# specific fragment it would get the un-updated document.
102+
# This recreates that case and asserts that we are using the
103+
# updated document like we should.
104+
105+
tool = load_tool(uri, loadingContext)
106+
107+
assert tool.tool["requirements"] == [
108+
{"class": "LoadListingRequirement", "loadListing": "no_listing"}
109+
]
110+
finally:
111+
use_standard_schema("v1.0")

tests/wf/packed-with-loadlisting.cwl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"$graph": [
3+
{
4+
"class": "Workflow",
5+
"requirements": [
6+
{
7+
"loadListing": "no_listing",
8+
"class": "http://commonwl.org/cwltool#LoadListingRequirement"
9+
}
10+
],
11+
"inputs": [
12+
{
13+
"type": "Directory",
14+
"id": "#main/d"
15+
}
16+
],
17+
"steps": [
18+
{
19+
"in": [
20+
{
21+
"source": "#main/d",
22+
"id": "#main/step1/d"
23+
}
24+
],
25+
"out": [
26+
"#main/step1/out"
27+
],
28+
"run": "#16169-step.cwl",
29+
"id": "#main/step1"
30+
}
31+
],
32+
"outputs": [
33+
{
34+
"type": "File",
35+
"outputSource": "#main/step1/out",
36+
"id": "#main/out"
37+
}
38+
],
39+
"id": "#main",
40+
"$namespaces": {
41+
"cwltool": "http://commonwl.org/cwltool#"
42+
}
43+
},
44+
{
45+
"class": "CommandLineTool",
46+
"requirements": [
47+
{
48+
"dockerPull": "debian:stretch-slim",
49+
"class": "DockerRequirement",
50+
},
51+
{
52+
"class": "InlineJavascriptRequirement"
53+
}
54+
],
55+
"inputs": [
56+
{
57+
"type": "Directory",
58+
"id": "#16169-step.cwl/d"
59+
}
60+
],
61+
"outputs": [
62+
{
63+
"type": "stdout",
64+
"id": "#16169-step.cwl/out"
65+
}
66+
],
67+
"stdout": "output.txt",
68+
"arguments": [
69+
"echo",
70+
"${if(inputs.d.listing === undefined) {return 'true';} else {return 'false';}}"
71+
],
72+
"id": "#16169-step.cwl"
73+
}
74+
],
75+
"cwlVersion": "v1.0"
76+
}

0 commit comments

Comments
 (0)