diff --git a/cwltool/cwlrdf.py b/cwltool/cwlrdf.py index 72948458c..b3b6739a5 100644 --- a/cwltool/cwlrdf.py +++ b/cwltool/cwlrdf.py @@ -1,14 +1,24 @@ import json import urlparse +from .process import Process from schema_salad.ref_resolver import Loader from schema_salad.jsonld_context import makerdf from rdflib import Graph, plugin, URIRef from rdflib.serializer import Serializer from typing import Any, Dict, IO, Text, Union -def printrdf(workflow, wf, ctx, sr, stdout): - # type: (Union[Text, Text], Union[List[Dict[Text, Any]], Dict[Text, Any]], Loader.ContextType, Text, IO[Any]) -> None - stdout.write(makerdf(workflow, wf, ctx).serialize(format=sr)) +def gather(tool, ctx): # type: (Process, Loader.ContextType) -> Graph + g = Graph() + + def visitor(t): + makerdf(t["id"], t, ctx, graph=g) + + tool.visit(visitor) + return g + +def printrdf(wf, ctx, sr, stdout): + # type: (Process, Loader.ContextType, Text, IO[Any]) -> None + stdout.write(gather(wf, ctx).serialize(format=sr)) def lastpart(uri): # type: (Any) -> Text uri = Text(uri) @@ -129,9 +139,9 @@ def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None WHERE { ?wf1 Workflow:steps ?src . ?wf2 Workflow:steps ?sink . - ?src cwl:outputs ?out . + ?src cwl:out ?out . ?inp cwl:source ?out . - ?sink cwl:inputs ?inp . + ?sink cwl:in ?inp . ?src cwl:run ?srcrun . ?sink cwl:run ?sinkrun . }""") @@ -147,9 +157,9 @@ def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None stdout.write(u'"%s" -> "%s" [%s]\n' % (dotname[src], dotname[sink], attr)) -def printdot(workflow, wf, ctx, stdout, include_parameters=False): - # type: (Union[Text, Text], Union[List[Dict[Text, Any]], Dict[Text, Any]], Loader.ContextType, Any, bool) -> None - g = makerdf(workflow, wf, ctx) +def printdot(wf, ctx, stdout, include_parameters=False): + # type: (Process, Loader.ContextType, Any, bool) -> None + g = gather(wf, ctx) stdout.write("digraph {") diff --git a/cwltool/main.py b/cwltool/main.py index 52f86bd24..5ca672f0a 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -598,16 +598,17 @@ def main(argsl=None, stdout.write(json.dumps(processobj, indent=4)) return 0 + tool = make_tool(document_loader, avsc_names, metadata, uri, + makeTool, vars(args)) + if args.print_rdf: - printrdf(uri, processobj, document_loader.ctx, args.rdf_serializer, stdout) + printrdf(tool, document_loader.ctx, args.rdf_serializer, stdout) return 0 if args.print_dot: - printdot(uri, processobj, document_loader.ctx, stdout) + printdot(tool, document_loader.ctx, stdout) return 0 - tool = make_tool(document_loader, avsc_names, metadata, uri, - makeTool, vars(args)) except (validate.ValidationException) as exc: _logger.error(u"Tool definition failed validation:\n%s", exc, exc_info=args.debug) diff --git a/cwltool/process.py b/cwltool/process.py index 10763e0c3..ac778dfd5 100644 --- a/cwltool/process.py +++ b/cwltool/process.py @@ -561,7 +561,7 @@ def validate_hints(self, avsc_names, hints, strict): def get_requirement(self, feature): # type: (Any) -> Tuple[Any, bool] return get_feature(self, feature) - def visit(self, op): + def visit(self, op): # type: (Callable[[Dict[Text, Any]], None]) -> None op(self.tool) @abc.abstractmethod diff --git a/setup.py b/setup.py index 50b0789fb..6c341e4ee 100755 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ 'rdflib >= 4.1.0', 'rdflib-jsonld >= 0.3.0', 'shellescape', - 'schema-salad==1.17.20160820171034', + 'schema-salad >= 1.18', 'typing >= 3.5.2', 'cwltest >= 1.0.20160907111242'], test_suite='tests',