11import urllib
22from codecs import StreamWriter
3- from typing import Any , Dict , Optional , TextIO , Union , cast
3+ from typing import Any , Dict , Iterator , Optional , TextIO , Union , cast
44
55from rdflib import Graph
6+ from rdflib .query import ResultRow
67from ruamel .yaml .comments import CommentedMap
78from schema_salad .jsonld_context import makerdf
89from schema_salad .utils import ContextType
@@ -26,7 +27,7 @@ def printrdf(wflow: Process, ctx: ContextType, style: str) -> str:
2627 rdf = gather (wflow , ctx ).serialize (format = style , encoding = "utf-8" )
2728 if not rdf :
2829 return ""
29- return cast ( str , rdf .decode ("utf-8" ) )
30+ return rdf .decode ("utf-8" )
3031
3132
3233def lastpart (uri : Any ) -> str :
@@ -37,28 +38,34 @@ def lastpart(uri: Any) -> str:
3738
3839
3940def 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
4245 WHERE {
4346 ?step cwl:run ?run .
4447 ?run rdf:type ?runtype .
4548 }"""
46- )
49+ ),
50+ ) # ResultRow because the query is of type SELECT
4751
4852 for step , run , _ in qres :
4953 stdout .write (
5054 '"%s" [label="%s"]\n '
5155 % (lastpart (step ), f"{ lastpart (step )} ({ lastpart (run )} )" )
5256 )
5357
54- qres = g .query (
55- """SELECT ?step ?inp ?source
58+ qres = cast (
59+ Iterator [ResultRow ],
60+ g .query (
61+ """SELECT ?step ?inp ?source
5662 WHERE {
5763 ?wf Workflow:steps ?step .
5864 ?step cwl:inputs ?inp .
5965 ?inp cwl:source ?source .
6066 }"""
61- )
67+ ),
68+ ) # ResultRow because the query is of type SELECT
6269
6370 for step , inp , source in qres :
6471 stdout .write ('"%s" [shape=box]\n ' % (lastpart (inp )))
@@ -69,41 +76,50 @@ def dot_with_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> None:
6976 '"{}" -> "{}" [label="{}"]\n ' .format (lastpart (inp ), lastpart (step ), "" )
7077 )
7178
72- qres = g .query (
73- """SELECT ?step ?out
79+ qres = cast (
80+ Iterator [ResultRow ],
81+ g .query (
82+ """SELECT ?step ?out
7483 WHERE {
7584 ?wf Workflow:steps ?step .
7685 ?step cwl:outputs ?out .
7786 }"""
78- )
87+ ),
88+ ) # ResultRow because the query is of type SELECT
7989
8090 for step , out in qres :
8191 stdout .write ('"%s" [shape=box]\n ' % (lastpart (out )))
8292 stdout .write (
8393 '"{}" -> "{}" [label="{}"]\n ' .format (lastpart (step ), lastpart (out ), "" )
8494 )
8595
86- qres = g .query (
87- """SELECT ?out ?source
96+ qres = cast (
97+ Iterator [ResultRow ],
98+ g .query (
99+ """SELECT ?out ?source
88100 WHERE {
89101 ?wf cwl:outputs ?out .
90102 ?out cwl:source ?source .
91103 }"""
92- )
104+ ),
105+ ) # ResultRow because the query is of type SELECT
93106
94107 for out , source in qres :
95108 stdout .write ('"%s" [shape=octagon]\n ' % (lastpart (out )))
96109 stdout .write (
97110 '"{}" -> "{}" [label="{}"]\n ' .format (lastpart (source ), lastpart (out ), "" )
98111 )
99112
100- qres = g .query (
101- """SELECT ?inp
113+ qres = cast (
114+ Iterator [ResultRow ],
115+ g .query (
116+ """SELECT ?inp
102117 WHERE {
103118 ?wf rdf:type cwl:Workflow .
104119 ?wf cwl:inputs ?inp .
105120 }"""
106- )
121+ ),
122+ ) # ResultRow because the query is of type SELECT
107123
108124 for (inp ,) in qres :
109125 stdout .write ('"%s" [shape=octagon]\n ' % (lastpart (inp )))
@@ -116,27 +132,33 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
116132 stdout .write ("compound=true\n " )
117133
118134 subworkflows = set ()
119- qres = g .query (
120- """SELECT ?run
135+ qres = cast (
136+ Iterator [ResultRow ],
137+ g .query (
138+ """SELECT ?run
121139 WHERE {
122140 ?wf rdf:type cwl:Workflow .
123141 ?wf Workflow:steps ?step .
124142 ?step cwl:run ?run .
125143 ?run rdf:type cwl:Workflow .
126144 } ORDER BY ?wf"""
127- )
145+ ),
146+ ) # ResultRow because the query is of type SELECT
128147 for (run ,) in qres :
129148 subworkflows .add (run )
130149
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
133154 WHERE {
134155 ?wf rdf:type cwl:Workflow .
135156 ?wf Workflow:steps ?step .
136157 ?step cwl:run ?run .
137158 ?run rdf:type ?runtype .
138159 } ORDER BY ?wf"""
139- )
160+ ),
161+ ) # ResultRow because the query is of type SELECT
140162
141163 currentwf = None # type: Optional[str]
142164 for wf , step , _run , runtype in qres :
@@ -164,8 +186,10 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
164186 if currentwf is not None :
165187 stdout .write ("}\n " )
166188
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
169193 WHERE {
170194 ?wf1 Workflow:steps ?src .
171195 ?wf2 Workflow:steps ?sink .
@@ -175,7 +199,8 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
175199 ?src cwl:run ?srcrun .
176200 ?sink cwl:run ?sinkrun .
177201 }"""
178- )
202+ ),
203+ ) # ResultRow because the query is of type SELECT
179204
180205 for src , sink , srcrun , sinkrun in qres :
181206 attr = ""
0 commit comments