Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dvc: handle multiline command as list #5194

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor thing: What should we do in the dvc.lock file? Should we keep them in a single format (like either a list or a multiline?)? Just that when the user changes the multiline string to a list or vice versa, it should not affect the lock file.

It might be too much to support that way, but just saying that in principle, it'd be better to have a single format in the lock file, but I think it happens rarely in practice and the list and the multiline string might never be equivalent when user refactors them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skshetry Great point! This PR still uses old schema where we save the cmd as is, but it makes total sense to just enforce the list in the new lock format. I guess we can do it in #5128 ?



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