Skip to content

Commit 854637d

Browse files
committed
impossible to have non-dict hints, reqs, or steps here
schema-salad catches that before the updater runs
1 parent ed6ba74 commit 854637d

File tree

1 file changed

+35
-75
lines changed

1 file changed

+35
-75
lines changed

cwltool/update.py

Lines changed: 35 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -29,61 +29,38 @@ def v1_2to1_3dev1(
2929

3030
def rewrite_loop_requirements(t: CWLObjectType) -> None:
3131
for s in cast(MutableSequence[CWLObjectType], t["steps"]):
32-
if isinstance(s, MutableMapping):
33-
if "requirements" in s:
34-
for i, r in enumerate(
35-
list(cast(MutableSequence[CWLObjectType], s["requirements"]))
36-
):
37-
if isinstance(r, MutableMapping):
38-
cls = cast(str, r["class"])
39-
if cls == "http://commonwl.org/cwltool#Loop":
40-
if "when" in s:
41-
raise SourceLine(
42-
s, "when", ValidationException
43-
).makeError(
44-
"The `cwltool:Loop` clause is not compatible with the `when` directive."
45-
)
46-
if "loopWhen" not in r:
47-
raise SourceLine(
48-
r, raise_type=ValidationException
49-
).makeError(
50-
"The `loopWhen` clause is mandatory within the `cwltool:Loop` requirement."
51-
)
52-
s["when"] = r["loopWhen"]
53-
if "loop" in r:
54-
s["loop"] = r["loop"]
55-
if "outputMethod" in r:
56-
s["outputMethod"] = r["outputMethod"]
57-
cast(
58-
MutableSequence[CWLObjectType],
59-
s["requirements"],
60-
).pop(index=i)
61-
else:
62-
raise SourceLine(s, i, ValidationException).makeError(
63-
"requirements entries must be dictionaries: {} {}.".format(
64-
type(r), r
65-
)
32+
if "requirements" in s:
33+
for i, r in enumerate(
34+
list(cast(MutableSequence[CWLObjectType], s["requirements"]))
35+
):
36+
cls = cast(str, r["class"])
37+
if cls == "http://commonwl.org/cwltool#Loop":
38+
if "when" in s:
39+
raise SourceLine(s, "when", ValidationException).makeError(
40+
"The `cwltool:Loop` clause is not compatible with the `when` directive."
6641
)
67-
if "hints" in s:
68-
for r in cast(MutableSequence[CWLObjectType], s["hints"]):
69-
if isinstance(r, MutableMapping):
70-
cls = cast(str, r["class"])
71-
if cls == "http://commonwl.org/cwltool#Loop":
72-
raise SourceLine(
73-
s["hints"], r, ValidationException
74-
).makeError(
75-
"http://commonwl.org/cwltool#Loop is valid only under requirements."
76-
)
77-
else:
42+
if "loopWhen" not in r:
7843
raise SourceLine(
79-
s["hints"], r, ValidationException
44+
r, raise_type=ValidationException
8045
).makeError(
81-
f"hints entries must be dictionaries: {type(r)} {r}."
46+
"The `loopWhen` clause is mandatory within the `cwltool:Loop` requirement."
8247
)
83-
else:
84-
raise SourceLine(t["steps"], s, ValidationException).makeError(
85-
f"steps entries must be dictionaries: {type(s)} {s}."
86-
)
48+
s["when"] = r["loopWhen"]
49+
if "loop" in r:
50+
s["loop"] = r["loop"]
51+
if "outputMethod" in r:
52+
s["outputMethod"] = r["outputMethod"]
53+
cast(
54+
MutableSequence[CWLObjectType],
55+
s["requirements"],
56+
).pop(index=i)
57+
if "hints" in s:
58+
for r in cast(MutableSequence[CWLObjectType], s["hints"]):
59+
cls = cast(str, r["class"])
60+
if cls == "http://commonwl.org/cwltool#Loop":
61+
raise SourceLine(s["hints"], r, ValidationException).makeError(
62+
"http://commonwl.org/cwltool#Loop is valid only under requirements."
63+
)
8764

8865
visit_class(doc, "Workflow", rewrite_loop_requirements)
8966
return (doc, "v1.3.0-dev1")
@@ -123,34 +100,17 @@ def v1_0to1_1(
123100
def rewrite_requirements(t: CWLObjectType) -> None:
124101
if "requirements" in t:
125102
for r in cast(MutableSequence[CWLObjectType], t["requirements"]):
126-
if isinstance(r, MutableMapping):
127-
cls = cast(str, r["class"])
128-
if cls in rewrite:
129-
r["class"] = rewrite[cls]
130-
else:
131-
raise ValidationException(
132-
"requirements entries must be dictionaries: {} {}.".format(
133-
type(r), r
134-
)
135-
)
103+
cls = cast(str, r["class"])
104+
if cls in rewrite:
105+
r["class"] = rewrite[cls]
136106
if "hints" in t:
137107
for r in cast(MutableSequence[CWLObjectType], t["hints"]):
138-
if isinstance(r, MutableMapping):
139-
cls = cast(str, r["class"])
140-
if cls in rewrite:
141-
r["class"] = rewrite[cls]
142-
else:
143-
raise ValidationException(
144-
f"hints entries must be dictionaries: {type(r)} {r}."
145-
)
108+
cls = cast(str, r["class"])
109+
if cls in rewrite:
110+
r["class"] = rewrite[cls]
146111
if "steps" in t:
147112
for s in cast(MutableSequence[CWLObjectType], t["steps"]):
148-
if isinstance(s, MutableMapping):
149-
rewrite_requirements(s)
150-
else:
151-
raise ValidationException(
152-
f"steps entries must be dictionaries: {type(s)} {s}."
153-
)
113+
rewrite_requirements(s)
154114

155115
def update_secondaryFiles(t, top=False):
156116
# type: (CWLOutputType, bool) -> Union[MutableSequence[MutableMapping[str, str]], MutableMapping[str, str]]

0 commit comments

Comments
 (0)