Skip to content

Commit

Permalink
fix(core): fix error when using external file in plan (#2815)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Apr 8, 2022
1 parent a0aa0bb commit 101209c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions renku/core/workflow/plan_factory.py
Expand Up @@ -285,6 +285,12 @@ def add_outputs(self, candidates: Set[Tuple[Union[Path, str], Optional[str]]]):
input_path = Path(os.path.abspath(path)).relative_to(self.working_dir)
except FileNotFoundError:
continue
except ValueError:
# NOTE: Raised if path is not relative to working_dir (external file)
input_path = Path(parameter.default_value)

if not input_path.exists():
continue

if input_path.is_dir() and tree.get(input_path):
# The directory might exist before running the script
Expand Down
27 changes: 27 additions & 0 deletions tests/cli/test_run.py
Expand Up @@ -18,9 +18,11 @@
"""Test ``run`` command."""

import os
from typing import cast

import pytest

from renku.domain_model.workflow.plan import Plan
from renku.infrastructure.gateway.activity_gateway import ActivityGateway
from renku.infrastructure.gateway.plan_gateway import PlanGateway
from renku.ui.cli import cli
Expand Down Expand Up @@ -118,6 +120,31 @@ def test_run_metadata(renku_cli, runner, client, client_database_injection_manag
assert 0 == result.exit_code, format_result_exception(result)


def test_run_external_file(renku_cli, runner, client, client_database_injection_manager, tmpdir):
"""Test run with workflow metadata."""

external_file = tmpdir.join("file_1")
external_file.write(str(1))

exit_code, activity = renku_cli("run", "--name", "run-1", "cp", str(external_file), "file_1")

assert 0 == exit_code
plan = activity.association.plan
assert "run-1" == plan.name

with client_database_injection_manager(client):
plan_gateway = PlanGateway()
plan = cast(Plan, plan_gateway.get_by_id(plan.id))
assert "run-1" == plan.name
assert 1 == len(plan.parameters)
assert 1 == len(plan.outputs)
assert 0 == len(plan.inputs)
assert plan.parameters[0].default_value == str(external_file)

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


@pytest.mark.parametrize(
"command, name",
[
Expand Down

0 comments on commit 101209c

Please sign in to comment.