dvc: handle multiline command as list (#5194)

Implements an approach proposed by @skshetry.

Fixes #4373
This commit is contained in:
Ruslan Kuprieiev
2021-01-04 09:11:57 +02:00
committed by GitHub
parent 764960fbfc
commit 7df53e5e26
2 changed files with 19 additions and 15 deletions
+1 -1
View File
@@ -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):
+18 -14
View File
@@ -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(
"""\
@@ -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"