Skip to content

Do not strip newline character for files created in InitWorkDir #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cwltool/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ def generate_arg(self, binding): # type: (Dict[Text,Any]) -> List[Text]

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

def do_eval(self, ex, context=None, pull_image=True, recursive=False):
# type: (Union[Dict[Text, Text], Text], Any, bool, bool) -> Any
def do_eval(self, ex, context=None, pull_image=True, recursive=False, strip_whitespace=True):
# type: (Union[Dict[Text, Text], Text], Any, bool, bool, bool) -> Any
if recursive:
if isinstance(ex, dict):
return {k: self.do_eval(v, context, pull_image, recursive) for k, v in iteritems(ex)}
Expand All @@ -268,4 +268,5 @@ def do_eval(self, ex, context=None, pull_image=True, recursive=False):
timeout=self.timeout,
debug=self.debug,
js_console=self.js_console,
force_docker_pull=self.force_docker_pull)
force_docker_pull=self.force_docker_pull,
strip_whitespace=strip_whitespace)
2 changes: 1 addition & 1 deletion cwltool/draft2tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
else:
for t in initialWorkdir["listing"]:
if "entry" in t:
et = {u"entry": builder.do_eval(t["entry"])}
et = {u"entry": builder.do_eval(t["entry"], strip_whitespace=False)}
if "entryname" in t:
et["entryname"] = builder.do_eval(t["entryname"])
else:
Expand Down
15 changes: 9 additions & 6 deletions cwltool/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ def evaluator(ex, jslib, obj, fullJS=False, timeout=None, force_docker_pull=Fals

def interpolate(scan, rootvars,
timeout=None, fullJS=None, jslib="", force_docker_pull=False,
debug=False, js_console=False):
# type: (Text, Dict[Text, Any], int, bool, Union[str, Text], bool, bool, bool) -> JSON
scan = scan.strip()
debug=False, js_console=False, strip_whitespace=True):
# type: (Text, Dict[Text, Any], int, bool, Union[str, Text], bool, bool, bool, bool) -> JSON
if strip_whitespace:
scan = scan.strip()
parts = []
w = scanner(scan)
while w:
Expand All @@ -202,8 +203,9 @@ def interpolate(scan, rootvars,


def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
context=None, pull_image=True, timeout=None, force_docker_pull=False, debug=False, js_console=False):
# 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
context=None, pull_image=True, timeout=None, force_docker_pull=False,
debug=False, js_console=False, strip_whitespace=True):
# 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

runtime = copy.copy(resources)
runtime["tmpdir"] = docker_windows_path_adjust(tmpdir)
Expand Down Expand Up @@ -231,7 +233,8 @@ def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
jslib=jslib,
force_docker_pull=force_docker_pull,
debug=debug,
js_console=js_console)
js_console=js_console,
strip_whitespace=strip_whitespace)

except Exception as e:
raise WorkflowException("Expression evaluation error:\n%s" % e)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_iwdr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

import cwltool
import cwltool.factory
from .util import get_data


class TestInitialWorkDir(unittest.TestCase):

def test_newline_in_entry(self):
"""
test that files in InitialWorkingDirectory are created with a newline character
"""
f = cwltool.factory.Factory()
echo = f.make(get_data("tests/wf/iwdr-entry.cwl"))
self.assertEqual(echo(message="hello"), {"out": "CONFIGVAR=hello\n"})
22 changes: 22 additions & 0 deletions tests/wf/iwdr-entry.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env cwl-runner

class: CommandLineTool
cwlVersion: v1.0
baseCommand: ["cat", "example.conf"]

requirements:
InitialWorkDirRequirement:
listing:
- entryname: example.conf
entry: |
CONFIGVAR=$(inputs.message)

inputs:
message: string
outputs:
out:
type: string
outputBinding:
glob: example.conf
loadContents: true
outputEval: $(self[0].contents)