Skip to content

Support array of integers and floats as command argument parameters #2037

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 9 commits into from
Sep 9, 2024
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
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 @@
action = DirectoryAppendAction
else:
action = AppendAction
items = inptype["items"]
if items == "int" or items == "long":
atype = int

Check warning on line 908 in cwltool/argparser.py

View check run for this annotation

Codecov / codecov/patch

cwltool/argparser.py#L908

Added line #L908 was not covered by tests
elif items == "double" or items == "float":
atype = float

Check warning on line 910 in cwltool/argparser.py

View check run for this annotation

Codecov / codecov/patch

cwltool/argparser.py#L910

Added line #L910 was not covered by tests
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