Skip to content

Commit

Permalink
Fix --print-rdf to include dependent documents (tools etc) in graph (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
tetron authored Sep 7, 2016
1 parent abcfc09 commit 2b3d2ec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
26 changes: 18 additions & 8 deletions cwltool/cwlrdf.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 .
}""")
Expand All @@ -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 {")

Expand Down
9 changes: 5 additions & 4 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2b3d2ec

Please sign in to comment.