Skip to content

Commit

Permalink
Support array of integers and floats as command argument parameters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-tan authored Sep 9, 2024
1 parent 6d8c2a4 commit 2621312
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cwltool/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "float":
atype = float
elif isinstance(inptype, MutableMapping) and inptype["type"] == "enum":
atype = str
elif isinstance(inptype, MutableMapping) and inptype["type"] == "record":
Expand Down
81 changes: 81 additions & 0 deletions tests/test_toolargparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,62 @@
outputs: []
"""

script_int = """
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: ExpressionTool
inputs:
foo: int[]
expression: '{"bar": $(inputs.foo)}'
outputs: []
"""

script_long = """
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: ExpressionTool
inputs:
foo: long[]
expression: '{"bar": $(inputs.foo)}'
outputs: []
"""

script_float = """
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: ExpressionTool
inputs:
foo: float[]
expression: '{"bar": $(inputs.foo)}'
outputs: []
"""

script_double = """
#!/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"]),
Expand All @@ -120,6 +176,31 @@
script_e,
lambda x: [x, "--foo", "http://example.com"],
),
(
"foo with int",
script_int,
lambda x: [x, "--foo", "1", "--foo", "2"],
),
(
"foo with long for large value",
script_long,
lambda x: [x, "--foo", str(2**31 + 10)],
),
(
"foo with long for small value",
script_long,
lambda x: [x, "--foo", str(-1 * (2**31) - 10)],
),
(
"foo with float",
script_float,
lambda x: [x, "--foo", "1.2", "--foo", "3.4"],
),
(
"foo with double",
script_double,
lambda x: [x, "--foo", "1.2", "--foo", "3.4"],
),
]


Expand Down

0 comments on commit 2621312

Please sign in to comment.