From 7324015a585eed7066a36468425733ae78c28c57 Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 10:17:01 +0900 Subject: [PATCH 1/9] Support array of integers and floats as command argument parameters --- cwltool/argparser.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cwltool/argparser.py b/cwltool/argparser.py index f9d98e32d..29e281dd9 100644 --- a/cwltool/argparser.py +++ b/cwltool/argparser.py @@ -903,6 +903,11 @@ def add_argument( action = DirectoryAppendAction else: action = AppendAction + items = inptype["items"] + if items == "int" or items == "long": + atype = int + elif items == "double" or items == "fload": + atype = float elif isinstance(inptype, MutableMapping) and inptype["type"] == "enum": atype = str elif isinstance(inptype, MutableMapping) and inptype["type"] == "record": From acd6a1b037eacf1ed2d516977de167ae5a52d214 Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 10:27:03 +0900 Subject: [PATCH 2/9] Add tests --- tests/test_toolargparse.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index 756c373e8..ae190ae50 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -101,6 +101,34 @@ outputs: [] """ +script_f = """ +#!/usr/bin/env cwl-runner + +cwlVersion: v1.0 +class: ExpressionTool + +inputs: + foo: int[] + +expression: '{"bar": $(inputs.foo)}' + +outputs: [] +""" + +script_g = """ +#!/usr/bin/env cwl-runner + +cwlVersion: v1.0 +class: ExpressionTool + +inputs: + foo: double[] + +expression: '{"bar": $(inputs.foo)}' + +outputs: [] +""" + scripts_argparse_params = [ ("help", script_a, lambda x: ["--debug", x, "--input", get_data("tests/echo.cwl")]), ("boolean", script_b, lambda x: [x, "--help"]), @@ -120,6 +148,16 @@ script_e, lambda x: [x, "--foo", "http://example.com"], ), + ( + "foo with f", + script_f, + lambda x: [x, "--foo", "1", "--foo", "2"], + ), + ( + "foo with g", + script_g, + lambda x: [x, "--foo", "1.2", "--foo", "3.4"], + ), ] From 28ad046a455f078ce16b9ddea7af20958e8e819d Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 11:13:38 +0900 Subject: [PATCH 3/9] Add tests for large number and small number --- tests/test_toolargparse.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index ae190ae50..447117c7d 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -153,6 +153,16 @@ script_f, lambda x: [x, "--foo", "1", "--foo", "2"], ), + ( + "foo with f for long value (large number)", + script_f, + lambda x: [x, "--foo", str(2**31+10)], + ), + ( + "foo with f for long value (small number)", + script_f, + lambda x: [x, "--foo", str(-1*(2**31)-10)], + ), ( "foo with g", script_g, From 8e8b09f822e0c7f813ade6acd366e54a0abc54c9 Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 11:15:02 +0900 Subject: [PATCH 4/9] Fix style --- tests/test_toolargparse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index 447117c7d..69d5f4131 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -156,12 +156,12 @@ ( "foo with f for long value (large number)", script_f, - lambda x: [x, "--foo", str(2**31+10)], + lambda x: [x, "--foo", str(2**31 + 10)], ), ( "foo with f for long value (small number)", script_f, - lambda x: [x, "--foo", str(-1*(2**31)-10)], + lambda x: [x, "--foo", str(-1 * (2**31) - 10)], ), ( "foo with g", From 388d77aba864ee9b7dce461b1ad9ddfa57333737 Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 11:18:43 +0900 Subject: [PATCH 5/9] Fix typo --- cwltool/argparser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cwltool/argparser.py b/cwltool/argparser.py index 29e281dd9..efced5386 100644 --- a/cwltool/argparser.py +++ b/cwltool/argparser.py @@ -906,7 +906,7 @@ def add_argument( items = inptype["items"] if items == "int" or items == "long": atype = int - elif items == "double" or items == "fload": + elif items == "double" or items == "float": atype = float elif isinstance(inptype, MutableMapping) and inptype["type"] == "enum": atype = str From 29c22657b9f523fdb7a9a7df074716b77cb7184e Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 11:20:02 +0900 Subject: [PATCH 6/9] Add tests for long[] and float[] --- tests/test_toolargparse.py | 39 +++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index 69d5f4131..95075a614 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -121,6 +121,34 @@ cwlVersion: v1.0 class: ExpressionTool +inputs: + foo: long[] + +expression: '{"bar": $(inputs.foo)}' + +outputs: [] +""" + +script_h = """ +#!/usr/bin/env cwl-runner + +cwlVersion: v1.0 +class: ExpressionTool + +inputs: + foo: float[] + +expression: '{"bar": $(inputs.foo)}' + +outputs: [] +""" + +script_i = """ +#!/usr/bin/env cwl-runner + +cwlVersion: v1.0 +class: ExpressionTool + inputs: foo: double[] @@ -154,17 +182,22 @@ lambda x: [x, "--foo", "1", "--foo", "2"], ), ( - "foo with f for long value (large number)", + "foo with g for long value (large number)", script_f, lambda x: [x, "--foo", str(2**31 + 10)], ), ( - "foo with f for long value (small number)", + "foo with g for long value (small number)", script_f, lambda x: [x, "--foo", str(-1 * (2**31) - 10)], ), ( - "foo with g", + "foo with h", + script_g, + lambda x: [x, "--foo", "1.2", "--foo", "3.4"], + ), + ( + "foo with i", script_g, lambda x: [x, "--foo", "1.2", "--foo", "3.4"], ), From d30b2e1bf3d38c0d6881e2cbfadcb1675965cd56 Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 11:28:04 +0900 Subject: [PATCH 7/9] Fix input documents --- tests/test_toolargparse.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index 95075a614..378695e3f 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -183,22 +183,22 @@ ), ( "foo with g for long value (large number)", - script_f, + script_g, lambda x: [x, "--foo", str(2**31 + 10)], ), ( "foo with g for long value (small number)", - script_f, + script_g, lambda x: [x, "--foo", str(-1 * (2**31) - 10)], ), ( "foo with h", - script_g, + script_h, lambda x: [x, "--foo", "1.2", "--foo", "3.4"], ), ( "foo with i", - script_g, + script_i, lambda x: [x, "--foo", "1.2", "--foo", "3.4"], ), ] From b470db7232b1f512dae6dc8c4041763d8f5408ea Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 11:58:50 +0900 Subject: [PATCH 8/9] Update tests/test_toolargparse.py Co-authored-by: Michael R. Crusoe <1330696+mr-c@users.noreply.github.com> --- tests/test_toolargparse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index 378695e3f..cf9d6e96e 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -101,7 +101,7 @@ outputs: [] """ -script_f = """ +script_int = """ #!/usr/bin/env cwl-runner cwlVersion: v1.0 From ef396ee7648cbbc02490987e22f86a0b65a58ac3 Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 29 Aug 2024 12:00:27 +0900 Subject: [PATCH 9/9] Use better names --- tests/test_toolargparse.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index cf9d6e96e..11ce5e3db 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -115,7 +115,7 @@ outputs: [] """ -script_g = """ +script_long = """ #!/usr/bin/env cwl-runner cwlVersion: v1.0 @@ -129,7 +129,7 @@ outputs: [] """ -script_h = """ +script_float = """ #!/usr/bin/env cwl-runner cwlVersion: v1.0 @@ -143,7 +143,7 @@ outputs: [] """ -script_i = """ +script_double = """ #!/usr/bin/env cwl-runner cwlVersion: v1.0 @@ -177,28 +177,28 @@ lambda x: [x, "--foo", "http://example.com"], ), ( - "foo with f", - script_f, + "foo with int", + script_int, lambda x: [x, "--foo", "1", "--foo", "2"], ), ( - "foo with g for long value (large number)", - script_g, + "foo with long for large value", + script_long, lambda x: [x, "--foo", str(2**31 + 10)], ), ( - "foo with g for long value (small number)", - script_g, + "foo with long for small value", + script_long, lambda x: [x, "--foo", str(-1 * (2**31) - 10)], ), ( - "foo with h", - script_h, + "foo with float", + script_float, lambda x: [x, "--foo", "1.2", "--foo", "3.4"], ), ( - "foo with i", - script_i, + "foo with double", + script_double, lambda x: [x, "--foo", "1.2", "--foo", "3.4"], ), ]