Skip to content

Commit 741afe7

Browse files
authored
Merge pull request #825 from wtsi-hgi/fix-823
Fix #823 (file contents interpreted as bytes)
2 parents 1ed01a1 + 8004370 commit 741afe7

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

cwltool/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def bind_input(self,
282282
self.files.append(datum)
283283
if (binding and binding.get("loadContents")) or schema.get("loadContents"):
284284
with self.fs_access.open(datum["location"], "rb") as f:
285-
datum["contents"] = f.read(CONTENT_LIMIT)
285+
datum["contents"] = f.read(CONTENT_LIMIT).decode("utf-8")
286286

287287
if "secondaryFiles" in schema:
288288
if "secondaryFiles" not in datum:

cwltool/command_line_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def collect_output(self,
685685
if binding.get("loadContents") or compute_checksum:
686686
contents = f.read(CONTENT_LIMIT)
687687
if binding.get("loadContents"):
688-
files["contents"] = contents
688+
files["contents"] = contents.decode("utf-8")
689689
if compute_checksum:
690690
checksum = hashlib.sha1()
691691
while contents != b"":

cwltool/expression.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ def jshead(engine_config, rootvars):
1919

2020
# make sure all the byte strings are converted
2121
# to str in `rootvars` dict.
22-
# TODO: need to make sure the `rootvars dict`
23-
# contains no bytes type in the first place.
24-
if six.PY3:
25-
rootvars = bytes2str_in_dicts(rootvars) # type: ignore
2622

2723
return u"\n".join(
2824
engine_config + [u"var {} = {};".format(k, json_dumps(v, indent=4))
@@ -271,6 +267,11 @@ def do_eval(ex, # type: Union[Text, Dict]
271267
u"self": context,
272268
u"runtime": runtime}
273269

270+
# TODO: need to make sure the `rootvars dict`
271+
# contains no bytes type in the first place.
272+
if six.PY3:
273+
rootvars = bytes2str_in_dicts(rootvars) # type: ignore
274+
274275
if needs_parsing(ex):
275276
assert isinstance(ex, string_types)
276277
fullJS = False

cwltool/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def postScatterEval(io):
336336
for k, v in io.items():
337337
if k in loadContents and v.get("contents") is None:
338338
with fs_access.open(v["location"], "rb") as f:
339-
v["contents"] = f.read(CONTENT_LIMIT)
339+
v["contents"] = f.read(CONTENT_LIMIT).decode("utf-8")
340340

341341
def valueFromFunc(k, v): # type: (Any, Any) -> Any
342342
if k in valueFrom:

0 commit comments

Comments
 (0)