mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 15:28:34 +01:00
dvc: handle multiline command as list (#5194)
Implements an approach proposed by @skshetry. Fixes #4373
This commit is contained in:
+1
-1
@@ -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):
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user