From f1824219a13b8367ac2fdd4b475d12ceba97b7b7 Mon Sep 17 00:00:00 2001 From: Michael Franklin Date: Tue, 21 Apr 2020 17:38:40 +1000 Subject: [PATCH 1/6] Add `sep` function for joining array --- WDL/StdLib.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WDL/StdLib.py b/WDL/StdLib.py index 77c4986f..54bb7aff 100644 --- a/WDL/StdLib.py +++ b/WDL/StdLib.py @@ -77,6 +77,10 @@ def sub(input: Value.String, pattern: Value.String, replace: Value.String) -> Va def defined(v: Value.Base): return Value.Boolean(not isinstance(v, Value.Null)) + @static([Type.Array(Type.String()), Type.String()], Type.String()) + def sep(iterable: Value.Array, sep: Value.String) -> Value.String: + return Value.String(sep.value.join(v.value for v in iterable.value)) + # write_* static([Type.Array(Type.String())], Type.File(), "write_lines")( self._write(_serialize_lines) From 2ad42b0fa8efd12a384f50b9df49fd9111fc8287 Mon Sep 17 00:00:00 2001 From: Michael Franklin Date: Mon, 27 Apr 2020 17:08:52 +1000 Subject: [PATCH 2/6] Fix param ordering --- WDL/StdLib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WDL/StdLib.py b/WDL/StdLib.py index 54bb7aff..b7f7768d 100644 --- a/WDL/StdLib.py +++ b/WDL/StdLib.py @@ -77,8 +77,8 @@ def sub(input: Value.String, pattern: Value.String, replace: Value.String) -> Va def defined(v: Value.Base): return Value.Boolean(not isinstance(v, Value.Null)) - @static([Type.Array(Type.String()), Type.String()], Type.String()) - def sep(iterable: Value.Array, sep: Value.String) -> Value.String: + @static([Type.String(), Type.Array(Type.String())], Type.String()) + def sep(sep: Value.String, iterable: Value.Array) -> Value.String: return Value.String(sep.value.join(v.value for v in iterable.value)) # write_* From d090b48bb8f092c1eefc64b45e1114defd1acea0 Mon Sep 17 00:00:00 2001 From: Michael Franklin Date: Tue, 28 Apr 2020 10:29:57 +1000 Subject: [PATCH 3/6] Remove `sep` string interpolator from dev spec --- WDL/_grammar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WDL/_grammar.py b/WDL/_grammar.py index caf63589..9b2d6457 100644 --- a/WDL/_grammar.py +++ b/WDL/_grammar.py @@ -321,7 +321,7 @@ output_decls: "output" "{" bound_decl* "}" // WDL task commands: with {} and <<< >>> command and ${} and ~{} placeholder styles -!?placeholder_key: "default" | "false" | "true" | "sep" +!?placeholder_key: "default" | "false" | "true" ?placeholder_value: string_literal | INT -> int | FLOAT -> float From 2229c7c0c2debe94c55df39f086b699badb56c84 Mon Sep 17 00:00:00 2001 From: Michael Franklin Date: Tue, 28 Apr 2020 10:37:09 +1000 Subject: [PATCH 4/6] Remove all placeholders from WDL dev grammar --- WDL/_grammar.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/WDL/_grammar.py b/WDL/_grammar.py index 9b2d6457..d04fe024 100644 --- a/WDL/_grammar.py +++ b/WDL/_grammar.py @@ -321,12 +321,7 @@ output_decls: "output" "{" bound_decl* "}" // WDL task commands: with {} and <<< >>> command and ${} and ~{} placeholder styles -!?placeholder_key: "default" | "false" | "true" -?placeholder_value: string_literal - | INT -> int - | FLOAT -> float -placeholder_option: placeholder_key "=" placeholder_value -placeholder: placeholder_option* expr +placeholder: expr ?command: command1 | command2 From 2fde3e0889238ef3b55c5831e376a209da139122 Mon Sep 17 00:00:00 2001 From: Michael Franklin Date: Tue, 28 Apr 2020 10:52:26 +1000 Subject: [PATCH 5/6] Add sep test cases --- tests/test_5stdlib.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/test_5stdlib.py b/tests/test_5stdlib.py index 3c22c8fa..d57e1192 100644 --- a/tests/test_5stdlib.py +++ b/tests/test_5stdlib.py @@ -712,3 +712,46 @@ def test_zip_cross(self): } } """, expected_exception=WDL.Error.EvalError) + + def test_sep(self): + outputs = self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + output { + String out = sep(",", inp) + } + } + """) + self.assertEqual("value1,value2,value3", outputs["out"]) + + outputs = self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + command <<< + echo ~{sep(",", inp)} + >>> + + output { + String out = read_string(stdout()) + } + } + """) + self.assertEqual("value1,value2,value3", outputs["out"]) + + self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + command <<< + echo ~{sep="," inp} + >>> + } + """, expected_exception=WDL.Error.ValidationError) From a2389c96bdff537a1a995ebbba800b04e4a5a40c Mon Sep 17 00:00:00 2001 From: Michael Franklin Date: Tue, 28 Apr 2020 10:52:26 +1000 Subject: [PATCH 6/6] Add sep test cases --- tests/test_5stdlib.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_5stdlib.py b/tests/test_5stdlib.py index 3c22c8fa..6830c95d 100644 --- a/tests/test_5stdlib.py +++ b/tests/test_5stdlib.py @@ -712,3 +712,47 @@ def test_zip_cross(self): } } """, expected_exception=WDL.Error.EvalError) + + def test_sep(self): + outputs = self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + command {} + output { + String out = sep(",", inp) + } + } + """) + self.assertEqual("value1,value2,value3", outputs["out"]) + + outputs = self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + command <<< + echo ~{sep(",", inp)} + >>> + + output { + String out = read_string(stdout()) + } + } + """) + self.assertEqual("value1,value2,value3", outputs["out"]) + + self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + command <<< + echo ~{sep="," inp} + >>> + } + """, expected_exception=WDL.Error.SyntaxError)