From 91abc4fdb6030a3c09680de2db81647c5cd79adb Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Tue, 2 Dec 2025 15:58:10 +0100 Subject: [PATCH 1/2] printrdf: also include the input values --- cwltool/cwlrdf.py | 15 ++++++++++++--- cwltool/main.py | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) 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 4cbf356c7..f0db6fd45 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -1149,7 +1149,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 From ebe5fe305e22a8b3b3158669a428fdfce0cb9af1 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Tue, 2 Dec 2025 19:09:27 +0100 Subject: [PATCH 2/2] add a test --- tests/test_rdfprint.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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")