Skip to content

Commit a8d324b

Browse files
authored
Merge pull request #95 from common-workflow-language/scoped-ref-and-typedsl
Scoped ref and typedsl
2 parents 0a9524c + 23213e4 commit a8d324b

File tree

164 files changed

+4608
-1143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+4608
-1143
lines changed

cwltool/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class Builder(object):
3434
def __init__(self): # type: () -> None
3535
self.names = None # type: avro.schema.Names
3636
self.schemaDefs = None # type: Dict[str,Dict[unicode, Any]]
37-
self.files = None # type: List[Dict[str, str]]
37+
self.files = None # type: List[Dict[unicode, unicode]]
3838
self.fs_access = None # type: StdFsAccess
39-
self.job = None # type: Dict[str, Any]
39+
self.job = None # type: Dict[unicode, Union[Dict[unicode, Any], List, unicode]]
4040
self.requirements = None # type: List[Dict[str,Any]]
4141
self.outdir = None # type: str
4242
self.tmpdir = None # type: str

cwltool/cwlrdf.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Any, Union, Dict, IO
77

88
def makerdf(workflow, wf, ctx):
9-
# type: (Union[str, unicode], Dict[str,Any], Loader.ContextType) -> Graph
9+
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType) -> Graph
1010
prefixes = {}
1111
for k,v in ctx.iteritems():
1212
if isinstance(v, dict):
@@ -18,7 +18,11 @@ def makerdf(workflow, wf, ctx):
1818
p, _ = frg.split("/")
1919
prefixes[p] = u"%s#%s/" % (doc_url, p)
2020

21-
wf["@context"] = ctx
21+
if isinstance(wf, list):
22+
for entry in wf:
23+
entry["@context"] = ctx
24+
else:
25+
wf["@context"] = ctx
2226
g = Graph().parse(data=json.dumps(wf), format='json-ld', location=workflow)
2327

2428
# Bug in json-ld loader causes @id fields to be added to the graph
@@ -31,7 +35,7 @@ def makerdf(workflow, wf, ctx):
3135
return g
3236

3337
def printrdf(workflow, wf, ctx, sr, stdout):
34-
# type: (Union[str, unicode], Dict[str, Any], Loader.ContextType, str, IO[Any]) -> None
38+
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType, str, IO[Any]) -> None
3539
stdout.write(makerdf(workflow, wf, ctx).serialize(format=sr))
3640

3741
def lastpart(uri): # type: (Any) -> str
@@ -172,7 +176,7 @@ def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
172176

173177

174178
def printdot(workflow, wf, ctx, stdout, include_parameters=False):
175-
# type: (Union[str, unicode], Dict[str, Any], Loader.ContextType, Any, bool) -> None
179+
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType, Any, bool) -> None
176180
g = makerdf(workflow, wf, ctx)
177181

178182
stdout.write("digraph {")

cwltool/draft2tool.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class ExpressionTool(Process):
3232
def __init__(self, toolpath_object, **kwargs):
33-
# type: (Dict[str,List[None]], **Any) -> None
33+
# type: (Dict[unicode, Any], **Any) -> None
3434
super(ExpressionTool, self).__init__(toolpath_object, **kwargs)
3535

3636
class ExpressionJob(object):
@@ -53,7 +53,7 @@ def run(self, **kwargs): # type: (**Any) -> None
5353
self.output_callback({}, "permanentFail")
5454

5555
def job(self, joborder, output_callback, **kwargs):
56-
# type: (Dict[str,str], str, Callable[[Any, Any], Any], **Any) -> Generator[ExpressionTool.ExpressionJob, None, None]
56+
# type: (Dict[unicode, unicode], Callable[[Any, Any], Any], **Any) -> Generator[ExpressionTool.ExpressionJob, None, None]
5757
builder = self._init_job(joborder, **kwargs)
5858

5959
j = ExpressionTool.ExpressionJob()
@@ -113,14 +113,14 @@ def run(self, **kwargs):
113113

114114
class CommandLineTool(Process):
115115
def __init__(self, toolpath_object, **kwargs):
116-
# type: (Dict[str,Any], **Any) -> None
116+
# type: (Dict[unicode, Any], **Any) -> None
117117
super(CommandLineTool, self).__init__(toolpath_object, **kwargs)
118118

119119
def makeJobRunner(self): # type: () -> CommandLineJob
120120
return CommandLineJob()
121121

122122
def makePathMapper(self, reffiles, **kwargs):
123-
# type: (Set[str], str, **Any) -> PathMapper
123+
# type: (Set[unicode], **Any) -> PathMapper
124124
dockerReq, _ = self.get_requirement("DockerRequirement")
125125
try:
126126
if dockerReq and kwargs.get("use_container"):
@@ -132,7 +132,7 @@ def makePathMapper(self, reffiles, **kwargs):
132132
raise WorkflowException(u"Missing input file %s" % e)
133133

134134
def job(self, joborder, output_callback, **kwargs):
135-
# type: (Dict[str,str], str, Callable[..., Any], **Any) -> Generator[Union[CommandLineJob, CallbackJob], None, None]
135+
# type: (Dict[unicode, unicode], Callable[..., Any], **Any) -> Generator[Union[CommandLineJob, CallbackJob], None, None]
136136

137137
jobname = uniquename(kwargs.get("name", shortname(self.tool.get("id", "job"))))
138138

@@ -149,7 +149,7 @@ def job(self, joborder, output_callback, **kwargs):
149149
if docker_req and kwargs.get("use_container") is not False:
150150
dockerimg = docker_req.get("dockerImageId") or docker_req.get("dockerPull")
151151
cmdline = ["docker", "run", dockerimg] + cmdline
152-
keydict = {"cmdline": cmdline}
152+
keydict = {u"cmdline": cmdline}
153153

154154
for _,f in cachebuilder.pathmapper.items():
155155
st = os.stat(f[0])
@@ -200,7 +200,7 @@ def rm_pending_output_callback(output_callback, jobcachepending,
200200

201201
builder = self._init_job(joborder, **kwargs)
202202

203-
reffiles = set((f["path"] for f in builder.files))
203+
reffiles = set((f[u"path"] for f in builder.files))
204204

205205
j = self.makeJobRunner()
206206
j.builder = builder
@@ -298,9 +298,9 @@ def _check_adjust(f): # type: (Dict[str,Any]) -> Dict[str,Any]
298298
yield j
299299

300300
def collect_output_ports(self, ports, builder, outdir):
301-
# type: (Set[Dict[str,Any]], Builder, str) -> Dict[str,Union[str,List[Any],Dict[str,Any]]]
301+
# type: (Set[Dict[str,Any]], Builder, str) -> Dict[unicode, Union[unicode, List[Any], Dict[unicode, Any]]]
302302
try:
303-
ret = {} # type: Dict[str,Union[str,List[Any],Dict[str,Any]]]
303+
ret = {} # type: Dict[unicode, Union[unicode, List[Any], Dict[unicode, Any]]]
304304
custom_output = os.path.join(outdir, "cwl.output.json")
305305
if builder.fs_access.exists(custom_output):
306306
with builder.fs_access.open(custom_output, "r") as f:
@@ -329,7 +329,7 @@ def collect_output_ports(self, ports, builder, outdir):
329329
raise WorkflowException("Error validating output record, " + str(e) + "\n in " + json.dumps(ret, indent=4))
330330

331331
def collect_output(self, schema, builder, outdir):
332-
# type: (Dict[str,Any], Builder, str) -> Union[Dict[str, Any], List[Union[Dict[str, Any], str]]]
332+
# type: (Dict[str,Any], Builder, str) -> Union[Dict[unicode, Any], List[Union[Dict[unicode, Any], unicode]]]
333333
r = [] # type: List[Any]
334334
if "outputBinding" in schema:
335335
binding = schema["outputBinding"]

cwltool/expression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def jshead(engineConfig, rootvars):
1919
return u"\n".join(engineConfig + [u"var %s = %s;" % (k, json.dumps(v, indent=4)) for k, v in rootvars.items()])
2020

2121
def exeval(ex, jobinput, requirements, outdir, tmpdir, context, pull_image):
22-
# type: (Dict[str,Any], Dict[str,str], List[Dict[str, Any]], str, str, Any, bool) -> sandboxjs.JSON
22+
# type: (Dict[str, Any], Dict[unicode, Union[Dict, List, unicode]], List[Dict[str, Any]], str, str, Any, bool) -> sandboxjs.JSON
2323

2424
if ex["engine"] == "https://w3id.org/cwl/cwl#JavascriptEngine":
2525
engineConfig = [] # type: List[unicode]
@@ -126,7 +126,7 @@ def param_interpolate(ex, obj, strip=True):
126126

127127
def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
128128
context=None, pull_image=True, timeout=None):
129-
# type: (Any, Dict[str,str], List[Dict[str,Any]], str, str, Dict[str, Union[int, str]], Any, bool, int) -> Any
129+
# type: (Union[dict, unicode], Dict[unicode, Union[Dict, List, unicode]], List[Dict[str, Any]], str, str, Dict[str, Union[int, str]], Any, bool, int) -> Any
130130

131131
runtime = resources.copy()
132132
runtime["tmpdir"] = tmpdir
@@ -140,7 +140,7 @@ def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
140140

141141
if isinstance(ex, dict) and "engine" in ex and "script" in ex:
142142
return exeval(ex, jobinput, requirements, outdir, tmpdir, context, pull_image)
143-
if isinstance(ex, basestring):
143+
if isinstance(ex, (str, unicode)):
144144
for r in requirements:
145145
if r["class"] == "InlineJavascriptRequirement":
146146
return sandboxjs.interpolate(str(ex), jshead(r.get("expressionLib", []), rootvars),

cwltool/job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CommandLineJob(object):
4242

4343
def __init__(self): # type: () -> None
4444
self.builder = None # type: Builder
45-
self.joborder = None # type: Dict[str,str]
45+
self.joborder = None # type: Dict[unicode, Union[Dict[unicode, Any], List, unicode]]
4646
self.stdin = None # type: str
4747
self.stderr = None # type: str
4848
self.stdout = None # type: str

cwltool/load_tool.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def fetch_document(argsworkflow):
4444

4545
def validate_document(document_loader, workflowobj, uri,
4646
enable_dev=False, strict=True, preprocess_only=False):
47-
# type: (Loader, Dict[unicode, Any], unicode, bool, bool, bool) -> Tuple[Loader, Names, Any, Dict[str, str], unicode]
47+
# type: (Loader, Dict[unicode, Any], unicode, bool, bool, bool) -> Tuple[Loader, Names, Union[Dict[unicode, Any], List[Dict[unicode, Any]]], Dict[unicode, Any], unicode]
4848
"""Validate a CWL document."""
4949
jobobj = None
5050
if "cwl:tool" in workflowobj:
@@ -83,31 +83,34 @@ def validate_document(document_loader, workflowobj, uri,
8383

8484
workflowobj["id"] = fileuri
8585
processobj, metadata = document_loader.resolve_all(workflowobj, fileuri)
86+
if not isinstance(processobj, (dict, list)):
87+
raise validate.ValidationException("Workflow must be a dict or list.")
8688

8789
if not metadata:
90+
if not isinstance(processobj, dict):
91+
raise validate.ValidationException(
92+
"Draft-2 workflows must be a dict.")
8893
metadata = {"$namespaces": processobj.get("$namespaces", {}),
8994
"$schemas": processobj.get("$schemas", []),
9095
"cwlVersion": processobj["cwlVersion"]}
9196

9297
if preprocess_only:
9398
return document_loader, avsc_names, processobj, metadata, uri
9499

95-
document_loader.validate_links(processobj)
96100
schema.validate_doc(avsc_names, processobj, document_loader, strict)
97101

98102
if metadata.get("cwlVersion") != update.LATEST:
99103
processobj = update.update(
100104
processobj, document_loader, fileuri, enable_dev, metadata)
101105

102106
if jobobj:
103-
metadata["cwl:defaults"] = jobobj
107+
metadata[u"cwl:defaults"] = jobobj
104108

105109
return document_loader, avsc_names, processobj, metadata, uri
106110

107111

108-
def make_tool(document_loader, avsc_names, processobj, metadata, uri, makeTool,
109-
kwargs):
110-
# type: (Loader, Names, Dict[str, Any], Dict[str, Any], unicode, Callable[..., Process], Dict[str, Any]) -> Process
112+
def make_tool(document_loader, avsc_names, metadata, uri, makeTool, kwargs):
113+
# type: (Loader, Names, Dict[unicode, Any], unicode, Callable[..., Process], Dict[str, Any]) -> Process
111114
"""Make a Python CWL object."""
112115
resolveduri = document_loader.resolve_ref(uri)[0]
113116

@@ -121,7 +124,7 @@ def make_tool(document_loader, avsc_names, processobj, metadata, uri, makeTool,
121124
urlparse.urldefrag(i["id"])[1] for i in resolveduri
122125
if "id" in i))
123126
else:
124-
processobj = cast(Dict[str, Any], resolveduri)
127+
processobj = resolveduri
125128

126129
kwargs = kwargs.copy()
127130
kwargs.update({
@@ -149,5 +152,5 @@ def load_tool(argsworkflow, makeTool, kwargs=None,
149152
document_loader, avsc_names, processobj, metadata, uri = validate_document(
150153
document_loader, workflowobj, uri, enable_dev=enable_dev,
151154
strict=strict)
152-
return make_tool(document_loader, avsc_names, processobj, metadata, uri,
155+
return make_tool(document_loader, avsc_names, metadata, uri,
153156
makeTool, kwargs if kwargs else {})

0 commit comments

Comments
 (0)