Skip to content

Commit

Permalink
fix(core): fix using float values in renku workflow iterate (#2875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Apr 29, 2022
1 parent 8a07faf commit 07934a8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
10 changes: 7 additions & 3 deletions renku/core/workflow/converters/cwl.py
Expand Up @@ -267,7 +267,9 @@ def _convert_step(
dirents.append(path)
jsrequirement = True

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

environment_variables.append(cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{input_.name}", input_.actual_value))
environment_variables.append(
cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{input_.name}", str(input_.actual_value))
)
tool_object.inputs.append(tool_input)
if input_.mapped_to:
tool_object.stdin = "$(inputs.{}.path)".format(tool_input.id)
jsrequirement = True

for parameter in workflow.parameters:
environment_variables.append(
cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{parameter.name}", parameter.actual_value)
cwl.EnvironmentDef(f"{RENKU_ENV_PREFIX}{parameter.name}", str(parameter.actual_value))
)
tool_object.inputs.append(CWLExporter._convert_parameter(parameter))

Expand Down
10 changes: 10 additions & 0 deletions renku/data/shacl_shape.json
Expand Up @@ -1132,6 +1132,11 @@
"@id": "xsd:decimal"
}
},
{
"datatype": {
"@id": "xsd:double"
}
},
{
"datatype": {
"@id": "xsd:integer"
Expand Down Expand Up @@ -1359,6 +1364,11 @@
"nodeKind": "sh:Literal",
"path": "schema:value",
"or": [
{
"datatype": {
"@id": "xsd:double"
}
},
{
"datatype": {
"@id": "xsd:decimal"
Expand Down
42 changes: 42 additions & 0 deletions tests/cli/test_workflow.py
Expand Up @@ -1069,6 +1069,47 @@ def test_workflow_iterate(runner, run_shell, client, workflow, parameters, provi
assert 0 == result.exit_code, format_result_exception(result)


@pytest.mark.parametrize("provider", available_workflow_providers())
def test_workflow_iterate_command_with_parameter_set(runner, run_shell, project, capsys, client, provider):
"""Test executing a workflow with --set float value for a renku.ui.api.Parameter."""
script = client.path / "script.py"
output = client.path / "output"

with client.commit():
script.write_text("import sys\nprint(sys.argv[1])\n")

result = run_shell(f"renku run --name run1 -- python {script} 3.98 > {output}")

# Assert expected empty stdout.
assert b"" == result[0]
# Assert not allocated stderr.
assert result[1] is None

assert "3.98\n" == output.read_text()

result = run_shell(f"renku workflow execute -p {provider} --set parameter-2=2.0 run1")

# Assert not allocated stderr.
assert result[1] is None

assert "2.0\n" == output.read_text()

result = run_shell(f"renku workflow iterate -p {provider} --map parameter-2=[0.1,0.3,0.5,0.8,0.95] run1")

# Assert not allocated stderr.
assert result[1] is None
assert output.read_text() in [
"0.1\n",
"0.3\n",
"0.5\n",
"0.8\n",
"0.95\n",
]

result = runner.invoke(cli, ["graph", "export", "--format", "json-ld", "--strict"])
assert 0 == result.exit_code, format_result_exception(result)


def test_workflow_cycle_detection(run_shell, project, capsys, client):
"""Test creating a cycle is not possible with renku run or workflow execute."""
input = client.path / "input"
Expand Down Expand Up @@ -1151,6 +1192,7 @@ def test_workflow_execute_docker_toil_stderr(runner, client, run_shell):
],
)
def test_workflow_templated_params(runner, run_shell, client, capsys, workflow, parameters, provider, outputs):
"""Test executing a workflow with templated parameters."""
workflow_name = "foobar"

# Run a shell command with pipe.
Expand Down

0 comments on commit 07934a8

Please sign in to comment.