diff --git a/cwltool/cwlrdf.py b/cwltool/cwlrdf.py index 0b844df4a..890a1a3d3 100644 --- a/cwltool/cwlrdf.py +++ b/cwltool/cwlrdf.py @@ -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") diff --git a/cwltool/main.py b/cwltool/main.py index b8d74ded0..0e19a2899 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -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 diff --git a/tests/test_rdfprint.py b/tests/test_rdfprint.py index 63adb1c74..27c779f70 100644 --- a/tests/test_rdfprint.py +++ b/tests/test_rdfprint.py @@ -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")