Skip to content

Commit f09844a

Browse files
committed
add tool making kwargs to Factory
1 parent d558fe7 commit f09844a

File tree

6 files changed

+36
-27
lines changed

6 files changed

+36
-27
lines changed

cwltool/factory.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,28 @@ def __init__(self,
3838
makeTool=workflow.defaultMakeTool, # type: tCallable[[Any], Process]
3939
# should be tCallable[[Dict[Text, Any], Any], Process] ?
4040
executor=None, # type: tCallable[...,Tuple[Dict[Text,Any], Text]]
41-
**execkwargs # type: Any
41+
makekwargs={}, # type: Dict[Any, Any]
42+
**execkwargs # type: Dict[Any, Any]
4243
):
4344
# type: (...) -> None
4445
self.makeTool = makeTool
4546
if executor is None:
4647
executor = SingleJobExecutor()
4748
self.executor = executor
4849

49-
kwargs = get_default_args()
50-
kwargs.pop("job_order")
51-
kwargs.pop("workflow")
52-
kwargs.pop("outdir")
53-
kwargs.update(execkwargs)
54-
self.execkwargs = kwargs
50+
newExecKwargs = get_default_args()
51+
newExecKwargs.pop("job_order")
52+
newExecKwargs.pop("workflow")
53+
newExecKwargs.pop("outdir")
54+
newExecKwargs.update(execkwargs)
55+
self.execkwargs = newExecKwargs
56+
self.makekwargs = makekwargs
5557

5658
def make(self, cwl):
5759
"""Instantiate a CWL object from a CWl document."""
5860
load = load_tool.load_tool(cwl, self.makeTool,
59-
strict=self.execkwargs.get("strict", True))
61+
strict=self.execkwargs.get("strict", True),
62+
kwargs=self.makekwargs)
6063
if isinstance(load, int):
6164
raise Exception("Error loading tool")
6265
return Callable(load, self)

tests/test_examples.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import cwltool.workflow
3030
import schema_salad.validate
3131
from cwltool.main import main
32-
from cwltool.utils import onWindows, windows_default_container_id
32+
from cwltool.utils import onWindows
3333

34-
from .util import get_data, needs_docker
34+
from .util import get_data, needs_docker, get_windows_safe_factory
3535

3636
sys.argv = ['']
3737

@@ -136,20 +136,10 @@ def test_params(self):
136136
self.assertEqual(expr.interpolate("$(foo[\"b\\'ar\"].baz) $(foo[\"b\\'ar\"].baz)", inputs), "true true")
137137
self.assertEqual(expr.interpolate("$(foo['b\\\"ar'].baz) $(foo['b\\\"ar'].baz)", inputs), "null null")
138138

139-
def _find_default_container(default_container_id, builder):
140-
return default_container_id
141-
142-
143139
class TestFactory(unittest.TestCase):
144140

145141
def test_factory(self):
146-
if onWindows():
147-
opts = {'find_default_container': functools.partial(
148-
_find_default_container, windows_default_container_id),
149-
'use_container': True}
150-
else:
151-
opts = {}
152-
f = cwltool.factory.Factory(**opts)
142+
f = get_windows_safe_factory()
153143
echo = f.make(get_data("tests/echo.cwl"))
154144
self.assertEqual(echo(inp="foo"), {"out": "foo\n"})
155145

tests/test_iwdr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import cwltool
44
import cwltool.factory
5-
from .util import get_data
5+
from .util import get_data, get_windows_safe_factory
66

77

88
class TestInitialWorkDir(unittest.TestCase):
@@ -11,6 +11,6 @@ def test_newline_in_entry(self):
1111
"""
1212
test that files in InitialWorkingDirectory are created with a newline character
1313
"""
14-
f = cwltool.factory.Factory()
14+
f = get_windows_safe_factory()
1515
echo = f.make(get_data("tests/wf/iwdr-entry.cwl"))
1616
self.assertEqual(echo(message="hello"), {"out": "CONFIGVAR=hello\n"})

tests/test_js_sandbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
exec_js_process)
1414
import cwltool.sandboxjs
1515
from cwltool.utils import onWindows
16-
from .util import get_data
16+
from .util import get_data, get_windows_safe_factory
1717
import pytest
1818

1919

@@ -48,7 +48,7 @@ def test_is_javascript_installed(self):
4848
class TestValueFrom(unittest.TestCase):
4949

5050
def test_value_from_two_concatenated_expressions(self):
51-
f = cwltool.factory.Factory()
51+
f = get_windows_safe_factory()
5252
echo = f.make(get_data("tests/wf/vf-concat.cwl"))
5353
self.assertEqual(echo(), {u"out": u"a sting\n"})
5454

tests/test_parallel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import cwltool.factory
88
from cwltool.executors import MultithreadedJobExecutor
99
from cwltool.utils import onWindows
10-
from .util import get_data
10+
from .util import get_data, get_windows_safe_factory
1111

1212

1313
class TestParallel(unittest.TestCase):
@@ -27,7 +27,7 @@ def test_sequential_workflow(self):
2727
def test_scattered_workflow(self):
2828
test_file = "tests/wf/scatter-wf4.cwl"
2929
job_file = "tests/wf/scatter-job2.json"
30-
f = cwltool.factory.Factory(executor=MultithreadedJobExecutor())
30+
f = get_windows_safe_factory(executor=MultithreadedJobExecutor())
3131
echo = f.make(get_data(test_file))
3232
with open(get_data(job_file)) as job:
3333
self.assertEqual(echo(**json.load(job)), {'out': ['foo one three', 'foo two four']})

tests/util.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
import distutils.spawn
77
import pytest
88

9+
from cwltool.utils import onWindows
10+
from cwltool.factory import Factory
11+
12+
def get_windows_safe_factory(**execkwargs):
13+
if onWindows():
14+
opts = {'find_default_container': functools.partial(
15+
force_default_container, windows_default_container_id),
16+
'use_container': True,
17+
'default_container': windows_default_container_id}
18+
else:
19+
opts = {}
20+
return Factory(makekwargs=opts, **execkwargs)
21+
22+
def force_default_container(default_container_id, builder):
23+
return default_container_id
24+
925
def get_data(filename):
1026
filename = os.path.normpath(
1127
filename) # normalizing path depending on OS or else it will cause problem when joining path

0 commit comments

Comments
 (0)