Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions cwltool/cwlrdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,30 @@

from .cwlviewer import CWLViewer
from .process import Process
from .utils import CWLObjectType


def gather(tool: Process, ctx: ContextType) -> Graph:
def gather(tool: Process, ctx: ContextType, inputs: CWLObjectType | None = None) -> Graph:
"""Convert a Process with optional inputs object into a RDF Graph."""
g = Graph()

def visitor(t: CommentedMap) -> None:
makerdf(t["id"], t, ctx, graph=g)

if inputs:
for inp_name in inputs:
for inp in tool.tool["inputs"]:
if inp["id"].endswith(f"#{inp_name}"):
inp["rdf:value"] = inputs[inp_name]
tool.visit(visitor)
return g


def printrdf(wflow: Process, ctx: ContextType, style: str) -> str:
def printrdf(
wflow: Process, ctx: ContextType, style: str, inputs: CWLObjectType | None = None
) -> str:
"""Serialize the CWL document into a string, ready for printing."""
rdf = gather(wflow, ctx).serialize(format=style, encoding="utf-8")
rdf = gather(wflow, ctx, inputs).serialize(format=style, encoding="utf-8")
if not rdf:
return ""
return str(rdf, "utf-8")
Expand Down
4 changes: 3 additions & 1 deletion cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,9 @@ def main(

if args.print_rdf:
print(
printrdf(tool, loadingContext.loader.ctx, args.rdf_serializer),
printrdf(
tool, loadingContext.loader.ctx, args.rdf_serializer, job_order_object
),
file=stdout,
)
return 0
Expand Down
14 changes: 13 additions & 1 deletion tests/test_rdfprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@

from cwltool.main import main

from .util import get_data
from .util import get_data, get_main_output


def test_rdf_print() -> None:
assert main(["--print-rdf", get_data("tests/wf/hello_single_tool.cwl")]) == 0


def test_rdf_print_inputs_and_defaults() -> None:
error_code, stdout, stderr = get_main_output(
["--print-rdf", get_data("tests/wf/revsort.cwl"), get_data("tests/wf/revsort-job.json")]
)
assert error_code == 0, stderr
assert "revsort.cwl#workflow_input> rdf:value " in stdout
assert (
'tests/wf/revsort.cwl#workflow_input> rdfs:comment "The input file to be processed."'
not in stdout
)


def test_rdf_print_unicode(monkeypatch: pytest.MonkeyPatch) -> None:
"""Force ASCII encoding but load UTF file with --print-rdf."""
monkeypatch.setenv("LC_ALL", "C")
Expand Down
Loading