Skip to content

Commit af59ba2

Browse files
author
Anton Khodak
authored
Merge pull request #640 from common-workflow-language/whitespace-iwdr
Do not strip newline character for files created in InitWorkDir
2 parents d7a74eb + 5228a26 commit af59ba2

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

cwltool/builder.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ def generate_arg(self, binding): # type: (Dict[Text,Any]) -> List[Text]
252252

253253
return [a for a in args if a is not None]
254254

255-
def do_eval(self, ex, context=None, pull_image=True, recursive=False):
256-
# type: (Union[Dict[Text, Text], Text], Any, bool, bool) -> Any
255+
def do_eval(self, ex, context=None, pull_image=True, recursive=False, strip_whitespace=True):
256+
# type: (Union[Dict[Text, Text], Text], Any, bool, bool, bool) -> Any
257257
if recursive:
258258
if isinstance(ex, dict):
259259
return {k: self.do_eval(v, context, pull_image, recursive) for k, v in iteritems(ex)}
@@ -268,4 +268,5 @@ def do_eval(self, ex, context=None, pull_image=True, recursive=False):
268268
timeout=self.timeout,
269269
debug=self.debug,
270270
js_console=self.js_console,
271-
force_docker_pull=self.force_docker_pull)
271+
force_docker_pull=self.force_docker_pull,
272+
strip_whitespace=strip_whitespace)

cwltool/draft2tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
383383
else:
384384
for t in initialWorkdir["listing"]:
385385
if "entry" in t:
386-
et = {u"entry": builder.do_eval(t["entry"])}
386+
et = {u"entry": builder.do_eval(t["entry"], strip_whitespace=False)}
387387
if "entryname" in t:
388388
et["entryname"] = builder.do_eval(t["entryname"])
389389
else:

cwltool/expression.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,10 @@ def evaluator(ex, jslib, obj, fullJS=False, timeout=None, force_docker_pull=Fals
173173

174174
def interpolate(scan, rootvars,
175175
timeout=None, fullJS=None, jslib="", force_docker_pull=False,
176-
debug=False, js_console=False):
177-
# type: (Text, Dict[Text, Any], int, bool, Union[str, Text], bool, bool, bool) -> JSON
178-
scan = scan.strip()
176+
debug=False, js_console=False, strip_whitespace=True):
177+
# type: (Text, Dict[Text, Any], int, bool, Union[str, Text], bool, bool, bool, bool) -> JSON
178+
if strip_whitespace:
179+
scan = scan.strip()
179180
parts = []
180181
w = scanner(scan)
181182
while w:
@@ -202,8 +203,9 @@ def interpolate(scan, rootvars,
202203

203204

204205
def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
205-
context=None, pull_image=True, timeout=None, force_docker_pull=False, debug=False, js_console=False):
206-
# type: (Union[dict, AnyStr], Dict[Text, Union[Dict, List, Text]], List[Dict[Text, Any]], Text, Text, Dict[Text, Union[int, Text]], Any, bool, int, bool, bool, bool) -> Any
206+
context=None, pull_image=True, timeout=None, force_docker_pull=False,
207+
debug=False, js_console=False, strip_whitespace=True):
208+
# type: (Union[dict, AnyStr], Dict[Text, Union[Dict, List, Text]], List[Dict[Text, Any]], Text, Text, Dict[Text, Union[int, Text]], Any, bool, int, bool, bool, bool, bool) -> Any
207209

208210
runtime = copy.copy(resources)
209211
runtime["tmpdir"] = docker_windows_path_adjust(tmpdir)
@@ -231,7 +233,8 @@ def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
231233
jslib=jslib,
232234
force_docker_pull=force_docker_pull,
233235
debug=debug,
234-
js_console=js_console)
236+
js_console=js_console,
237+
strip_whitespace=strip_whitespace)
235238

236239
except Exception as e:
237240
raise WorkflowException("Expression evaluation error:\n%s" % e)

tests/test_iwdr.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
3+
import cwltool
4+
import cwltool.factory
5+
from .util import get_data
6+
7+
8+
class TestInitialWorkDir(unittest.TestCase):
9+
10+
def test_newline_in_entry(self):
11+
"""
12+
test that files in InitialWorkingDirectory are created with a newline character
13+
"""
14+
f = cwltool.factory.Factory()
15+
echo = f.make(get_data("tests/wf/iwdr-entry.cwl"))
16+
self.assertEqual(echo(message="hello"), {"out": "CONFIGVAR=hello\n"})

tests/wf/iwdr-entry.cwl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
class: CommandLineTool
4+
cwlVersion: v1.0
5+
baseCommand: ["cat", "example.conf"]
6+
7+
requirements:
8+
InitialWorkDirRequirement:
9+
listing:
10+
- entryname: example.conf
11+
entry: |
12+
CONFIGVAR=$(inputs.message)
13+
14+
inputs:
15+
message: string
16+
outputs:
17+
out:
18+
type: string
19+
outputBinding:
20+
glob: example.conf
21+
loadContents: true
22+
outputEval: $(self[0].contents)

0 commit comments

Comments
 (0)