From 4b609f2ecd8370d33a1638a2c631441dbf296431 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Sun, 5 Oct 2025 15:02:30 +0200 Subject: [PATCH 1/2] remove unused code --- cwltool/cwlrdf.py | 172 +--------------------------------------------- 1 file changed, 1 insertion(+), 171 deletions(-) diff --git a/cwltool/cwlrdf.py b/cwltool/cwlrdf.py index 126f0c780..def50ea59 100644 --- a/cwltool/cwlrdf.py +++ b/cwltool/cwlrdf.py @@ -1,10 +1,6 @@ -import urllib -from codecs import StreamWriter -from collections.abc import Iterator -from typing import IO, Any, Optional, TextIO, Union, cast +from typing import IO, Any from rdflib import Graph -from rdflib.query import ResultRow from ruamel.yaml.comments import CommentedMap from schema_salad.jsonld_context import makerdf from schema_salad.utils import ContextType @@ -38,172 +34,6 @@ def lastpart(uri: Any) -> str: return uri2 -def dot_with_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> None: - qres = cast( - Iterator[ResultRow], - g.query( - """SELECT ?step ?run ?runtype - WHERE { - ?step cwl:run ?run . - ?run rdf:type ?runtype . - }""" - ), - ) # ResultRow because the query is of type SELECT - - for step, run, _ in qres: - stdout.write( - '"{}" [label="{}"]\n'.format(lastpart(step), f"{lastpart(step)} ({lastpart(run)})") - ) - - qres = cast( - Iterator[ResultRow], - g.query( - """SELECT ?step ?inp ?source - WHERE { - ?wf Workflow:steps ?step . - ?step cwl:inputs ?inp . - ?inp cwl:source ?source . - }""" - ), - ) # ResultRow because the query is of type SELECT - - for step, inp, source in qres: - stdout.write('"%s" [shape=box]\n' % (lastpart(inp))) - stdout.write('"{}" -> "{}" [label="{}"]\n'.format(lastpart(source), lastpart(inp), "")) - stdout.write('"{}" -> "{}" [label="{}"]\n'.format(lastpart(inp), lastpart(step), "")) - - qres = cast( - Iterator[ResultRow], - g.query( - """SELECT ?step ?out - WHERE { - ?wf Workflow:steps ?step . - ?step cwl:outputs ?out . - }""" - ), - ) # ResultRow because the query is of type SELECT - - for step, out in qres: - stdout.write('"%s" [shape=box]\n' % (lastpart(out))) - stdout.write('"{}" -> "{}" [label="{}"]\n'.format(lastpart(step), lastpart(out), "")) - - qres = cast( - Iterator[ResultRow], - g.query( - """SELECT ?out ?source - WHERE { - ?wf cwl:outputs ?out . - ?out cwl:source ?source . - }""" - ), - ) # ResultRow because the query is of type SELECT - - for out, source in qres: - stdout.write('"%s" [shape=octagon]\n' % (lastpart(out))) - stdout.write('"{}" -> "{}" [label="{}"]\n'.format(lastpart(source), lastpart(out), "")) - - qres = cast( - Iterator[ResultRow], - g.query( - """SELECT ?inp - WHERE { - ?wf rdf:type cwl:Workflow . - ?wf cwl:inputs ?inp . - }""" - ), - ) # ResultRow because the query is of type SELECT - - for (inp,) in qres: - stdout.write('"%s" [shape=octagon]\n' % (lastpart(inp))) - - -def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> None: - dotname: dict[str, str] = {} - clusternode = {} - - stdout.write("compound=true\n") - - subworkflows = set() - qres = cast( - Iterator[ResultRow], - g.query( - """SELECT ?run - WHERE { - ?wf rdf:type cwl:Workflow . - ?wf Workflow:steps ?step . - ?step cwl:run ?run . - ?run rdf:type cwl:Workflow . - } ORDER BY ?wf""" - ), - ) # ResultRow because the query is of type SELECT - for (run,) in qres: - subworkflows.add(run) - - qres = cast( - Iterator[ResultRow], - g.query( - """SELECT ?wf ?step ?run ?runtype - WHERE { - ?wf rdf:type cwl:Workflow . - ?wf Workflow:steps ?step . - ?step cwl:run ?run . - ?run rdf:type ?runtype . - } ORDER BY ?wf""" - ), - ) # ResultRow because the query is of type SELECT - - currentwf: Optional[str] = None - for wf, step, _run, runtype in qres: - if step not in dotname: - dotname[step] = lastpart(step) - - if wf != currentwf: - if currentwf is not None: - stdout.write("}\n") - if wf in subworkflows: - if wf not in dotname: - dotname[wf] = "cluster_" + lastpart(wf) - stdout.write(f'subgraph "{dotname[wf]}" {{ label="{lastpart(wf)}"\n') # noqa: B907 - currentwf = wf - clusternode[wf] = step - else: - currentwf = None - - if str(runtype) != "https://w3id.org/cwl/cwl#Workflow": - stdout.write( - f'"{dotname[step]}" [label="{urllib.parse.urldefrag(str(step))[1]}"]\n' # noqa: B907 - ) - - if currentwf is not None: - stdout.write("}\n") - - qres = cast( - Iterator[ResultRow], - g.query( - """SELECT DISTINCT ?src ?sink ?srcrun ?sinkrun - WHERE { - ?wf1 Workflow:steps ?src . - ?wf2 Workflow:steps ?sink . - ?src cwl:out ?out . - ?inp cwl:source ?out . - ?sink cwl:in ?inp . - ?src cwl:run ?srcrun . - ?sink cwl:run ?sinkrun . - }""" - ), - ) # ResultRow because the query is of type SELECT - - for src, sink, srcrun, sinkrun in qres: - attr = "" - if srcrun in clusternode: - attr += 'ltail="%s"' % dotname[srcrun] - src = clusternode[srcrun] - if sinkrun in clusternode: - attr += ' lhead="%s"' % dotname[sinkrun] - sink = clusternode[sinkrun] - stdout.write(f'"{dotname[src]}" -> "{dotname[sink]}" [{attr}]\n') # noqa: B907 - - def printdot( wf: Process, ctx: ContextType, From af5026abe8a522fa8d46166ad6f32d08768254ac Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Sun, 5 Oct 2025 15:14:28 +0200 Subject: [PATCH 2/2] Improve the docs --- cwltool/cwlprov/ro.py | 1 + cwltool/cwlrdf.py | 2 ++ cwltool/factory.py | 1 + cwltool/job.py | 1 + cwltool/resolver.py | 3 +++ cwltool/stdfsaccess.py | 1 + 6 files changed, 9 insertions(+) diff --git a/cwltool/cwlprov/ro.py b/cwltool/cwlprov/ro.py index 19334d2b8..5bc846dac 100644 --- a/cwltool/cwlprov/ro.py +++ b/cwltool/cwlprov/ro.py @@ -402,6 +402,7 @@ def guess_mediatype( return aggregates def add_uri(self, uri: str, timestamp: Optional[datetime.datetime] = None) -> Aggregate: + """Add the given URI to this RO.""" self.self_check() aggr: Aggregate = {"uri": uri} aggr["createdOn"], aggr["createdBy"] = self._self_made(timestamp=timestamp) diff --git a/cwltool/cwlrdf.py b/cwltool/cwlrdf.py index def50ea59..0b844df4a 100644 --- a/cwltool/cwlrdf.py +++ b/cwltool/cwlrdf.py @@ -1,3 +1,5 @@ +"""RDF output.""" + from typing import IO, Any from rdflib import Graph diff --git a/cwltool/factory.py b/cwltool/factory.py index eaf98e3cf..08b57c00c 100644 --- a/cwltool/factory.py +++ b/cwltool/factory.py @@ -27,6 +27,7 @@ def __init__(self, t: Process, factory: "Factory") -> None: def __call__(self, **kwargs): # type: (**Any) -> Union[str, Optional[CWLObjectType]] + """Invoke the tool.""" runtime_context = self.factory.runtime_context.copy() runtime_context.basedir = os.getcwd() out, status = self.factory.executor(self.t, kwargs, runtime_context) diff --git a/cwltool/job.py b/cwltool/job.py index 075e27ef6..df695aeb2 100644 --- a/cwltool/job.py +++ b/cwltool/job.py @@ -100,6 +100,7 @@ def relink_initialworkdir( def neverquote(string: str, pos: int = 0, endpos: int = 0) -> Optional[Match[str]]: + """No-op.""" return None diff --git a/cwltool/resolver.py b/cwltool/resolver.py index 918a9b24e..83586e1da 100644 --- a/cwltool/resolver.py +++ b/cwltool/resolver.py @@ -11,6 +11,7 @@ def resolve_local(document_loader: Optional[Loader], uri: str) -> Optional[str]: + """Use the local resolver to find the target of the URI.""" pathpart, frag = urllib.parse.urldefrag(uri) try: @@ -41,6 +42,7 @@ def resolve_local(document_loader: Optional[Loader], uri: str) -> Optional[str]: def tool_resolver(document_loader: Loader, uri: str) -> Optional[str]: + """Try both the local resolver and the GA4GH TRS resolver, in that order.""" for r in [resolve_local, resolve_ga4gh_tool]: ret = r(document_loader, uri) if ret is not None: @@ -63,6 +65,7 @@ def tool_resolver(document_loader: Loader, uri: str) -> Optional[str]: def resolve_ga4gh_tool(document_loader: Loader, uri: str) -> Optional[str]: + """Use the GA4GH TRS API to resolve a tool reference.""" path, version = uri.partition(":")[::2] if not version: version = "latest" diff --git a/cwltool/stdfsaccess.py b/cwltool/stdfsaccess.py index c58257f63..dffa0cd85 100644 --- a/cwltool/stdfsaccess.py +++ b/cwltool/stdfsaccess.py @@ -55,6 +55,7 @@ def listdir(self, fn: str) -> list[str]: return [abspath(urllib.parse.quote(entry), fn) for entry in os.listdir(self._abs(fn))] def join(self, path, *paths): # type: (str, *str) -> str + """Join one or more path segments intelligently.""" return os.path.join(path, *paths) def realpath(self, path: str) -> str: