Skip to content

Commit 07934a8

Browse files
authored
fix(core): fix using float values in renku workflow iterate (#2875)
1 parent 8a07faf commit 07934a8

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

renku/core/workflow/converters/cwl.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ def _convert_step(
267267
dirents.append(path)
268268
jsrequirement = True
269269

270-
environment_variables.append(cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{output_.name}", output_.actual_value))
270+
environment_variables.append(
271+
cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{output_.name}", str(output_.actual_value))
272+
)
271273
outp, arg = CWLExporter._convert_output(output_)
272274
tool_object.outputs.append(outp)
273275
if arg:
@@ -280,15 +282,17 @@ def _convert_step(
280282
cwl.Dirent(entry="$(inputs.{})".format(tool_input.id), entryname=input_.actual_value, writable=False)
281283
)
282284

283-
environment_variables.append(cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{input_.name}", input_.actual_value))
285+
environment_variables.append(
286+
cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{input_.name}", str(input_.actual_value))
287+
)
284288
tool_object.inputs.append(tool_input)
285289
if input_.mapped_to:
286290
tool_object.stdin = "$(inputs.{}.path)".format(tool_input.id)
287291
jsrequirement = True
288292

289293
for parameter in workflow.parameters:
290294
environment_variables.append(
291-
cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{parameter.name}", parameter.actual_value)
295+
cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{parameter.name}", str(parameter.actual_value))
292296
)
293297
tool_object.inputs.append(CWLExporter._convert_parameter(parameter))
294298

renku/data/shacl_shape.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,11 @@
11321132
"@id": "xsd:decimal"
11331133
}
11341134
},
1135+
{
1136+
"datatype": {
1137+
"@id": "xsd:double"
1138+
}
1139+
},
11351140
{
11361141
"datatype": {
11371142
"@id": "xsd:integer"
@@ -1359,6 +1364,11 @@
13591364
"nodeKind": "sh:Literal",
13601365
"path": "schema:value",
13611366
"or": [
1367+
{
1368+
"datatype": {
1369+
"@id": "xsd:double"
1370+
}
1371+
},
13621372
{
13631373
"datatype": {
13641374
"@id": "xsd:decimal"

tests/cli/test_workflow.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,47 @@ def test_workflow_iterate(runner, run_shell, client, workflow, parameters, provi
10691069
assert 0 == result.exit_code, format_result_exception(result)
10701070

10711071

1072+
@pytest.mark.parametrize("provider", available_workflow_providers())
1073+
def test_workflow_iterate_command_with_parameter_set(runner, run_shell, project, capsys, client, provider):
1074+
"""Test executing a workflow with --set float value for a renku.ui.api.Parameter."""
1075+
script = client.path / "script.py"
1076+
output = client.path / "output"
1077+
1078+
with client.commit():
1079+
script.write_text("import sys\nprint(sys.argv[1])\n")
1080+
1081+
result = run_shell(f"renku run --name run1 -- python {script} 3.98 > {output}")
1082+
1083+
# Assert expected empty stdout.
1084+
assert b"" == result[0]
1085+
# Assert not allocated stderr.
1086+
assert result[1] is None
1087+
1088+
assert "3.98\n" == output.read_text()
1089+
1090+
result = run_shell(f"renku workflow execute -p {provider} --set parameter-2=2.0 run1")
1091+
1092+
# Assert not allocated stderr.
1093+
assert result[1] is None
1094+
1095+
assert "2.0\n" == output.read_text()
1096+
1097+
result = run_shell(f"renku workflow iterate -p {provider} --map parameter-2=[0.1,0.3,0.5,0.8,0.95] run1")
1098+
1099+
# Assert not allocated stderr.
1100+
assert result[1] is None
1101+
assert output.read_text() in [
1102+
"0.1\n",
1103+
"0.3\n",
1104+
"0.5\n",
1105+
"0.8\n",
1106+
"0.95\n",
1107+
]
1108+
1109+
result = runner.invoke(cli, ["graph", "export", "--format", "json-ld", "--strict"])
1110+
assert 0 == result.exit_code, format_result_exception(result)
1111+
1112+
10721113
def test_workflow_cycle_detection(run_shell, project, capsys, client):
10731114
"""Test creating a cycle is not possible with renku run or workflow execute."""
10741115
input = client.path / "input"
@@ -1151,6 +1192,7 @@ def test_workflow_execute_docker_toil_stderr(runner, client, run_shell):
11511192
],
11521193
)
11531194
def test_workflow_templated_params(runner, run_shell, client, capsys, workflow, parameters, provider, outputs):
1195+
"""Test executing a workflow with templated parameters."""
11541196
workflow_name = "foobar"
11551197

11561198
# Run a shell command with pipe.

0 commit comments

Comments
 (0)