Skip to content

Commit

Permalink
dvc: handle multiline command as list
Browse files Browse the repository at this point in the history
Implements an approach proposed by @skshetry.

Fixes iterative#4373
  • Loading branch information
efiop committed Jan 4, 2021
1 parent 764960f commit 08384d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dvc/stage/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def warn_if_fish(executable):

def _enforce_cmd_list(cmd):
assert cmd
return cmd if isinstance(cmd, list) else [cmd]
return cmd if isinstance(cmd, list) else cmd.splitlines()


def prepare_kwargs(stage, checkpoint_func=None):
Expand Down
32 changes: 18 additions & 14 deletions tests/func/test_repro_multistage.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,14 @@ def test_repro_multiple_params(tmp_dir, dvc):
assert dvc.reproduce(stage.addressing) == [stage]


def test_repro_list_of_commands_in_order(tmp_dir, dvc):
@pytest.mark.parametrize("multiline", [True, False])
def test_repro_list_of_commands_in_order(tmp_dir, dvc, multiline):
cmd = ["echo foo>foo", "echo bar>bar"]
if multiline:
cmd = "\n".join(cmd)

dump_yaml("dvc.yaml", {"stages": {"multi": {"cmd": cmd}}})

(tmp_dir / "dvc.yaml").write_text(
dedent(
"""\
Expand All @@ -546,19 +553,16 @@ def test_repro_list_of_commands_in_order(tmp_dir, dvc):
assert (tmp_dir / "bar").read_text() == "bar\n"


def test_repro_list_of_commands_raise_and_stops_after_failure(tmp_dir, dvc):
(tmp_dir / "dvc.yaml").write_text(
dedent(
"""\
stages:
multi:
cmd:
- echo foo>foo
- failed_command
- echo baz>bar
"""
)
)
@pytest.mark.parametrize("multiline", [True, False])
def test_repro_list_of_commands_raise_and_stops_after_failure(
tmp_dir, dvc, multiline
):
cmd = ["echo foo>foo", "failed_command", "echo baz>bar"]
if multiline:
cmd = "\n".join(cmd)

dump_yaml("dvc.yaml", {"stages": {"multi": {"cmd": cmd}}})

with pytest.raises(ReproductionError):
dvc.reproduce(targets=["multi"])
assert (tmp_dir / "foo").read_text() == "foo\n"
Expand Down

0 comments on commit 08384d0

Please sign in to comment.