Skip to content

Commit 7599c49

Browse files
committed
break cyclic dependency; remove unused engine code
1 parent ecac600 commit 7599c49

File tree

8 files changed

+22
-112
lines changed

8 files changed

+22
-112
lines changed

cwltool/builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import schema_salad.validate as validate
66
from typing import Any, Union
77
from .errors import WorkflowException
8-
from .process import StdFsAccess
8+
from .stdfsaccess import StdFsAccess
99

1010
CONTENT_LIMIT = 64 * 1024
1111

@@ -40,6 +40,7 @@ def __init__(self): # type: () -> None
4040
self.tmpdir = None # type: str
4141
self.resources = None # type: Dict[str,str]
4242
self.bindings = None # type: List[Dict[str,str]]
43+
self.timeout = None # type: int
4344

4445
def bind_input(self, schema, datum, lead_pos=[], tail_pos=[]):
4546
# type: (Dict[str,Any], Any, List[int], List[int]) -> List[Dict[str,str]]

cwltool/docker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import requests
55
import os
6-
from . import process
6+
from .errors import ProcessWorkflowException
77
import re
88
import tempfile
99
from typing import Any, Union
@@ -76,7 +76,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
7676
loadproc.stdin.close()
7777
rcode = loadproc.wait()
7878
if rcode != 0:
79-
raise process.WorkflowException(
79+
raise ProcessWorkflowException(
8080
"Docker load returned non-zero exit status %i"
8181
% (rcode))
8282
found = True
@@ -104,15 +104,15 @@ def get_from_requirements(r, req, pull_image, dry_run=False):
104104

105105
if errmsg:
106106
if req:
107-
raise process.WorkflowException(errmsg)
107+
raise ProcessWorkflowException(errmsg)
108108
else:
109109
return None
110110

111111
if get_image(r, pull_image, dry_run):
112112
return r["dockerImageId"]
113113
else:
114114
if req:
115-
raise process.WorkflowException(
115+
raise ProcessWorkflowException(
116116
"Docker image %s not found" % r["dockerImageId"])
117117

118118
return None

cwltool/draft2tool.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ class CommandLineTool(Process):
102102
def __init__(self, toolpath_object, **kwargs):
103103
super(CommandLineTool, self).__init__(toolpath_object, **kwargs)
104104

105-
def makeJobRunner(self):
106-
return CommandLineJob()
107-
108105
def makePathMapper(self, reffiles, input_basedir, **kwargs):
109106
dockerReq, _ = self.get_requirement("DockerRequirement")
110107
try:
@@ -147,7 +144,7 @@ def job(self, joborder, input_basedir, output_callback, **kwargs):
147144

148145
reffiles = set((f["path"] for f in builder.files))
149146

150-
j = self.makeJobRunner()
147+
j = CommandLineJob()
151148
j.builder = builder
152149
j.joborder = builder.job
153150
j.stdin = None

cwltool/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class WorkflowException(Exception):
22
pass
3+
4+
class ProcessWorkflowException(WorkflowException):
5+
pass

cwltool/expression.py

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from . import docker
21
import subprocess
32
import json
43
from .aslist import aslist
54
import logging
65
from .errors import WorkflowException
7-
from . import process
86
import schema_salad.ref_resolver
97
from . import sandboxjs
108
import re
@@ -19,79 +17,6 @@ def jshead(engineConfig, rootvars):
1917
for k, v in rootvars.items()])
2018

2119

22-
def exeval(ex, jobinput, requirements, outdir, tmpdir, context, pull_image):
23-
if ex["engine"] == "https://w3id.org/cwl/cwl#JsonPointer":
24-
try:
25-
obj = {"job": jobinput, "context": context,
26-
"outdir": outdir, "tmpdir": tmpdir}
27-
return schema_salad.ref_resolver.resolve_json_pointer(
28-
obj, ex["script"])
29-
except ValueError as v:
30-
raise WorkflowException("%s in %s" % (v, obj))
31-
32-
if ex["engine"] == "https://w3id.org/cwl/cwl#JavascriptEngine":
33-
engineConfig = [] # type: List[str]
34-
for r in reversed(requirements):
35-
if (r["class"] == "ExpressionEngineRequirement" and
36-
r["id"] == "https://w3id.org/cwl/cwl#JavascriptEngine"):
37-
engineConfig = r.get("engineConfig", [])
38-
break
39-
return sandboxjs.execjs(ex["script"], jshead(
40-
engineConfig, (jobinput, context, tmpdir, outdir)))
41-
42-
for r in reversed(requirements):
43-
if (r["class"] == "ExpressionEngineRequirement" and
44-
r["id"] == ex["engine"]):
45-
runtime = [] # type: List[str]
46-
47-
class DR(object):
48-
49-
def __init__(self):
50-
self.requirements = None # type: str
51-
self.hints = None # type: str
52-
53-
dr = DR()
54-
dr.requirements = r.get("requirements", [])
55-
dr.hints = r.get("hints", [])
56-
57-
(docker_req, docker_is_req) = process.get_feature(
58-
dr, "DockerRequirement")
59-
img_id = None
60-
if docker_req:
61-
img_id = docker.get_from_requirements(
62-
docker_req, docker_is_req, pull_image)
63-
if img_id:
64-
runtime = ["docker", "run", "-i", "--rm", img_id]
65-
66-
inp = {
67-
"script": ex["script"],
68-
"engineConfig": r.get("engineConfig", []),
69-
"job": jobinput,
70-
"context": context,
71-
"outdir": outdir,
72-
"tmpdir": tmpdir,
73-
}
74-
75-
_logger.debug("Invoking expression engine %s with %s",
76-
runtime + aslist(r["engineCommand"]),
77-
json.dumps(inp, indent=4))
78-
79-
sp = subprocess.Popen(runtime + aslist(r["engineCommand"]),
80-
shell=False,
81-
close_fds=True,
82-
stdin=subprocess.PIPE,
83-
stdout=subprocess.PIPE)
84-
85-
(stdoutdata, stderrdata) = sp.communicate(json.dumps(inp) + "\n\n")
86-
if sp.returncode != 0:
87-
raise WorkflowException("Expression engine returned non-zero "
88-
"exit code on evaluation of\n%s"
89-
% json.dumps(inp, indent=4))
90-
91-
return json.loads(stdoutdata)
92-
93-
raise WorkflowException("Unknown expression engine '%s'" % ex["engine"])
94-
9520
seg_symbol = r"""\w+"""
9621
seg_single = r"""\['([^']|\\')+'\]"""
9722
seg_double = r"""\["([^"]|\\")+"\]"""
@@ -150,9 +75,6 @@ def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
15075
"runtime": runtime
15176
}
15277

153-
if isinstance(ex, dict) and "engine" in ex and "script" in ex:
154-
return exeval(ex, jobinput, requirements, outdir, tmpdir, context,
155-
pull_image)
15678
if isinstance(ex, basestring):
15779
for r in requirements:
15880
if r["class"] == "InlineJavascriptRequirement":

cwltool/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import os
77
import sys
88
import logging
9-
from . import workflow
9+
from .default_make_tool import defaultMakeTool
10+
from .errors import WorkflowException
1011
import schema_salad.validate as validate
1112
import tempfile
1213
import schema_salad.jsonld_context
@@ -198,17 +199,16 @@ def output_callback(out, processStatus):
198199
if r:
199200
r.run(**kwargs)
200201
else:
201-
raise workflow.WorkflowException(
202-
"Workflow cannot make any more progress.")
203-
except workflow.WorkflowException:
202+
raise WorkflowException(
203+
"Workflow cannot make any more progress.")
204+
except WorkflowException:
204205
raise
205206
except Exception as e:
206207
_logger.exception("Got workflow error")
207-
raise workflow.WorkflowException("%s" % e, )
208+
raise WorkflowException("%s" % e, )
208209

209210
if final_status[0] != "success":
210-
raise workflow.WorkflowException(
211-
"Process status is %s" % (final_status))
211+
raise WorkflowException("Process status is %s" % (final_status))
212212

213213
return final_output[0]
214214

@@ -382,7 +382,7 @@ def load_tool(argsworkflow, updateonly, strict, makeTool, debug,
382382
_logger.error("Tool definition failed validation:\n%s",
383383
e, exc_info=(e if debug else False))
384384
return 1
385-
except (RuntimeError, workflow.WorkflowException) as e:
385+
except (RuntimeError, WorkflowException) as e:
386386
_logger.error("Tool definition failed initialization:\n%s",
387387
e, exc_info=(e if debug else False))
388388
return 1
@@ -493,7 +493,7 @@ def print_deps(fn):
493493

494494
def main(args=None,
495495
executor=single_job_executor,
496-
makeTool=workflow.defaultMakeTool,
496+
makeTool=defaultMakeTool,
497497
selectResources=None,
498498
parser=None,
499499
stdin=sys.stdin,
@@ -600,7 +600,7 @@ def main(args=None,
600600
_logger.error("Input object failed validation:\n%s",
601601
e, exc_info=(e if args.debug else False))
602602
return 1
603-
except workflow.WorkflowException as e:
603+
except WorkflowException as e:
604604
_logger.error("Workflow error, try again with --debug for more "
605605
"information:\n %s", e,
606606
exc_info=(e if args.debug else False))

cwltool/process.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import schema_salad.validate as validate
55
import copy
6+
import yaml
67
import logging
78
from .aslist import aslist
89
import schema_salad.schema

cwltool/workflow.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from . import draft2tool
1+
from .draft2tool import CommandLineTool, ExpressionTool
22
from .aslist import aslist
33
from .process import Process, empty_subtree, shortname, uniquename
44
from .errors import WorkflowException
@@ -21,20 +21,6 @@
2121
WorkflowStateItem = namedtuple('WorkflowStateItem', ['parameter', 'value'])
2222

2323

24-
def defaultMakeTool(toolpath_object, **kwargs):
25-
if not isinstance(toolpath_object, dict):
26-
raise WorkflowException("Not a dict: `%s`" % toolpath_object)
27-
if "class" in toolpath_object:
28-
if toolpath_object["class"] == "CommandLineTool":
29-
return draft2tool.CommandLineTool(toolpath_object, **kwargs)
30-
elif toolpath_object["class"] == "ExpressionTool":
31-
return draft2tool.ExpressionTool(toolpath_object, **kwargs)
32-
elif toolpath_object["class"] == "Workflow":
33-
return Workflow(toolpath_object, **kwargs)
34-
35-
raise WorkflowException(
36-
"Missing or invalid 'class' field in %s, expecting one of: "
37-
"CommandLineTool, ExpressionTool, Workflow" % toolpath_object["id"])
3824

3925

4026
def findfiles(wo, fn=None):

0 commit comments

Comments
 (0)