1
1
import urllib
2
2
from codecs import StreamWriter
3
- from typing import Any , Dict , Optional , TextIO , Union , cast
3
+ from typing import Any , Dict , Iterator , Optional , TextIO , Union , cast
4
4
5
5
from rdflib import Graph
6
+ from rdflib .query import ResultRow
6
7
from ruamel .yaml .comments import CommentedMap
7
8
from schema_salad .jsonld_context import makerdf
8
9
from schema_salad .utils import ContextType
@@ -26,7 +27,7 @@ def printrdf(wflow: Process, ctx: ContextType, style: str) -> str:
26
27
rdf = gather (wflow , ctx ).serialize (format = style , encoding = "utf-8" )
27
28
if not rdf :
28
29
return ""
29
- return cast ( str , rdf .decode ("utf-8" ) )
30
+ return rdf .decode ("utf-8" )
30
31
31
32
32
33
def lastpart (uri : Any ) -> str :
@@ -37,28 +38,34 @@ def lastpart(uri: Any) -> str:
37
38
38
39
39
40
def dot_with_parameters (g : Graph , stdout : Union [TextIO , StreamWriter ]) -> None :
40
- qres = g .query (
41
- """SELECT ?step ?run ?runtype
41
+ qres = cast (
42
+ Iterator [ResultRow ],
43
+ g .query (
44
+ """SELECT ?step ?run ?runtype
42
45
WHERE {
43
46
?step cwl:run ?run .
44
47
?run rdf:type ?runtype .
45
48
}"""
46
- )
49
+ ),
50
+ ) # ResultRow because the query is of type SELECT
47
51
48
52
for step , run , _ in qres :
49
53
stdout .write (
50
54
'"%s" [label="%s"]\n '
51
55
% (lastpart (step ), f"{ lastpart (step )} ({ lastpart (run )} )" )
52
56
)
53
57
54
- qres = g .query (
55
- """SELECT ?step ?inp ?source
58
+ qres = cast (
59
+ Iterator [ResultRow ],
60
+ g .query (
61
+ """SELECT ?step ?inp ?source
56
62
WHERE {
57
63
?wf Workflow:steps ?step .
58
64
?step cwl:inputs ?inp .
59
65
?inp cwl:source ?source .
60
66
}"""
61
- )
67
+ ),
68
+ ) # ResultRow because the query is of type SELECT
62
69
63
70
for step , inp , source in qres :
64
71
stdout .write ('"%s" [shape=box]\n ' % (lastpart (inp )))
@@ -69,41 +76,50 @@ def dot_with_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> None:
69
76
'"{}" -> "{}" [label="{}"]\n ' .format (lastpart (inp ), lastpart (step ), "" )
70
77
)
71
78
72
- qres = g .query (
73
- """SELECT ?step ?out
79
+ qres = cast (
80
+ Iterator [ResultRow ],
81
+ g .query (
82
+ """SELECT ?step ?out
74
83
WHERE {
75
84
?wf Workflow:steps ?step .
76
85
?step cwl:outputs ?out .
77
86
}"""
78
- )
87
+ ),
88
+ ) # ResultRow because the query is of type SELECT
79
89
80
90
for step , out in qres :
81
91
stdout .write ('"%s" [shape=box]\n ' % (lastpart (out )))
82
92
stdout .write (
83
93
'"{}" -> "{}" [label="{}"]\n ' .format (lastpart (step ), lastpart (out ), "" )
84
94
)
85
95
86
- qres = g .query (
87
- """SELECT ?out ?source
96
+ qres = cast (
97
+ Iterator [ResultRow ],
98
+ g .query (
99
+ """SELECT ?out ?source
88
100
WHERE {
89
101
?wf cwl:outputs ?out .
90
102
?out cwl:source ?source .
91
103
}"""
92
- )
104
+ ),
105
+ ) # ResultRow because the query is of type SELECT
93
106
94
107
for out , source in qres :
95
108
stdout .write ('"%s" [shape=octagon]\n ' % (lastpart (out )))
96
109
stdout .write (
97
110
'"{}" -> "{}" [label="{}"]\n ' .format (lastpart (source ), lastpart (out ), "" )
98
111
)
99
112
100
- qres = g .query (
101
- """SELECT ?inp
113
+ qres = cast (
114
+ Iterator [ResultRow ],
115
+ g .query (
116
+ """SELECT ?inp
102
117
WHERE {
103
118
?wf rdf:type cwl:Workflow .
104
119
?wf cwl:inputs ?inp .
105
120
}"""
106
- )
121
+ ),
122
+ ) # ResultRow because the query is of type SELECT
107
123
108
124
for (inp ,) in qres :
109
125
stdout .write ('"%s" [shape=octagon]\n ' % (lastpart (inp )))
@@ -116,27 +132,33 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
116
132
stdout .write ("compound=true\n " )
117
133
118
134
subworkflows = set ()
119
- qres = g .query (
120
- """SELECT ?run
135
+ qres = cast (
136
+ Iterator [ResultRow ],
137
+ g .query (
138
+ """SELECT ?run
121
139
WHERE {
122
140
?wf rdf:type cwl:Workflow .
123
141
?wf Workflow:steps ?step .
124
142
?step cwl:run ?run .
125
143
?run rdf:type cwl:Workflow .
126
144
} ORDER BY ?wf"""
127
- )
145
+ ),
146
+ ) # ResultRow because the query is of type SELECT
128
147
for (run ,) in qres :
129
148
subworkflows .add (run )
130
149
131
- qres = g .query (
132
- """SELECT ?wf ?step ?run ?runtype
150
+ qres = cast (
151
+ Iterator [ResultRow ],
152
+ g .query (
153
+ """SELECT ?wf ?step ?run ?runtype
133
154
WHERE {
134
155
?wf rdf:type cwl:Workflow .
135
156
?wf Workflow:steps ?step .
136
157
?step cwl:run ?run .
137
158
?run rdf:type ?runtype .
138
159
} ORDER BY ?wf"""
139
- )
160
+ ),
161
+ ) # ResultRow because the query is of type SELECT
140
162
141
163
currentwf = None # type: Optional[str]
142
164
for wf , step , _run , runtype in qres :
@@ -164,8 +186,10 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
164
186
if currentwf is not None :
165
187
stdout .write ("}\n " )
166
188
167
- qres = g .query (
168
- """SELECT DISTINCT ?src ?sink ?srcrun ?sinkrun
189
+ qres = cast (
190
+ Iterator [ResultRow ],
191
+ g .query (
192
+ """SELECT DISTINCT ?src ?sink ?srcrun ?sinkrun
169
193
WHERE {
170
194
?wf1 Workflow:steps ?src .
171
195
?wf2 Workflow:steps ?sink .
@@ -175,7 +199,8 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
175
199
?src cwl:run ?srcrun .
176
200
?sink cwl:run ?sinkrun .
177
201
}"""
178
- )
202
+ ),
203
+ ) # ResultRow because the query is of type SELECT
179
204
180
205
for src , sink , srcrun , sinkrun in qres :
181
206
attr = ""
0 commit comments