Skip to content

Commit 2b3d2ec

Browse files
authored
Fix --print-rdf to include dependent documents (tools etc) in graph (#180)
* Fix --print-rdf to include dependent documents (tools etc) in graph, and update --print-dot for CWL v1.0 * Fix type annotations * Bump schema salad dependency, make version pin less restrictive.
1 parent abcfc09 commit 2b3d2ec

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

cwltool/cwlrdf.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import json
22
import urlparse
3+
from .process import Process
34
from schema_salad.ref_resolver import Loader
45
from schema_salad.jsonld_context import makerdf
56
from rdflib import Graph, plugin, URIRef
67
from rdflib.serializer import Serializer
78
from typing import Any, Dict, IO, Text, Union
89

9-
def printrdf(workflow, wf, ctx, sr, stdout):
10-
# type: (Union[Text, Text], Union[List[Dict[Text, Any]], Dict[Text, Any]], Loader.ContextType, Text, IO[Any]) -> None
11-
stdout.write(makerdf(workflow, wf, ctx).serialize(format=sr))
10+
def gather(tool, ctx): # type: (Process, Loader.ContextType) -> Graph
11+
g = Graph()
12+
13+
def visitor(t):
14+
makerdf(t["id"], t, ctx, graph=g)
15+
16+
tool.visit(visitor)
17+
return g
18+
19+
def printrdf(wf, ctx, sr, stdout):
20+
# type: (Process, Loader.ContextType, Text, IO[Any]) -> None
21+
stdout.write(gather(wf, ctx).serialize(format=sr))
1222

1323
def lastpart(uri): # type: (Any) -> Text
1424
uri = Text(uri)
@@ -129,9 +139,9 @@ def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
129139
WHERE {
130140
?wf1 Workflow:steps ?src .
131141
?wf2 Workflow:steps ?sink .
132-
?src cwl:outputs ?out .
142+
?src cwl:out ?out .
133143
?inp cwl:source ?out .
134-
?sink cwl:inputs ?inp .
144+
?sink cwl:in ?inp .
135145
?src cwl:run ?srcrun .
136146
?sink cwl:run ?sinkrun .
137147
}""")
@@ -147,9 +157,9 @@ def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
147157
stdout.write(u'"%s" -> "%s" [%s]\n' % (dotname[src], dotname[sink], attr))
148158

149159

150-
def printdot(workflow, wf, ctx, stdout, include_parameters=False):
151-
# type: (Union[Text, Text], Union[List[Dict[Text, Any]], Dict[Text, Any]], Loader.ContextType, Any, bool) -> None
152-
g = makerdf(workflow, wf, ctx)
160+
def printdot(wf, ctx, stdout, include_parameters=False):
161+
# type: (Process, Loader.ContextType, Any, bool) -> None
162+
g = gather(wf, ctx)
153163

154164
stdout.write("digraph {")
155165

cwltool/main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,16 +598,17 @@ def main(argsl=None,
598598
stdout.write(json.dumps(processobj, indent=4))
599599
return 0
600600

601+
tool = make_tool(document_loader, avsc_names, metadata, uri,
602+
makeTool, vars(args))
603+
601604
if args.print_rdf:
602-
printrdf(uri, processobj, document_loader.ctx, args.rdf_serializer, stdout)
605+
printrdf(tool, document_loader.ctx, args.rdf_serializer, stdout)
603606
return 0
604607

605608
if args.print_dot:
606-
printdot(uri, processobj, document_loader.ctx, stdout)
609+
printdot(tool, document_loader.ctx, stdout)
607610
return 0
608611

609-
tool = make_tool(document_loader, avsc_names, metadata, uri,
610-
makeTool, vars(args))
611612
except (validate.ValidationException) as exc:
612613
_logger.error(u"Tool definition failed validation:\n%s", exc,
613614
exc_info=args.debug)

cwltool/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def validate_hints(self, avsc_names, hints, strict):
561561
def get_requirement(self, feature): # type: (Any) -> Tuple[Any, bool]
562562
return get_feature(self, feature)
563563

564-
def visit(self, op):
564+
def visit(self, op): # type: (Callable[[Dict[Text, Any]], None]) -> None
565565
op(self.tool)
566566

567567
@abc.abstractmethod

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
'rdflib >= 4.1.0',
4747
'rdflib-jsonld >= 0.3.0',
4848
'shellescape',
49-
'schema-salad==1.17.20160820171034',
49+
'schema-salad >= 1.18',
5050
'typing >= 3.5.2',
5151
'cwltest >= 1.0.20160907111242'],
5252
test_suite='tests',

0 commit comments

Comments
 (0)