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

bugfix: rerun stage when command is changed #3922

Merged
merged 1 commit into from
Jun 1, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dvc/stage/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _is_cached(stage):
cached = (
not stage.is_callback
and not stage.always_changed
and not stage.changed_stage()
and stage.already_cached()
)
if cached:
Expand Down
22 changes: 22 additions & 0 deletions tests/func/test_repro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1770,3 +1770,25 @@ def test_ssh_dir_out(tmp_dir, dvc, ssh_server):

repo.reproduce("dir-out.dvc")
repo.reproduce("dir-out.dvc", force=True)


def test_repro_when_cmd_changes(tmp_dir, dvc, run_copy, mocker):
from dvc.dvcfile import SingleStageFile

tmp_dir.gen("foo", "foo")
stage = run_copy("foo", "bar", single_stage=True)
assert not dvc.reproduce(stage.addressing)

from dvc.stage.run import cmd_run

m = mocker.patch("dvc.stage.run.cmd_run", wraps=cmd_run)

data = SingleStageFile(dvc, stage.path)._load()[0]
data["cmd"] = " ".join(stage.cmd.split()) # change cmd spacing by two
dump_stage_file(stage.path, data)

assert dvc.status([stage.addressing]) == {
stage.addressing: ["changed checksum"]
}
assert dvc.reproduce(stage.addressing)[0] == stage
m.assert_called_once_with(stage)
6 changes: 5 additions & 1 deletion tests/func/test_repro_multistage.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,23 @@ def test_downstream(tmp_dir, dvc):
)


def test_repro_when_cmd_changes(tmp_dir, dvc, run_copy):
def test_repro_when_cmd_changes(tmp_dir, dvc, run_copy, mocker):
from dvc.dvcfile import PipelineFile

tmp_dir.gen("foo", "foo")
stage = run_copy("foo", "bar", name="copy-file")
target = "copy-file"
assert not dvc.reproduce(target)

from dvc.stage.run import cmd_run

m = mocker.patch("dvc.stage.run.cmd_run", wraps=cmd_run)
stage.cmd = " ".join(stage.cmd.split()) # change cmd spacing by two
PipelineFile(dvc, PIPELINE_FILE)._dump_pipeline_file(stage)

assert dvc.status([target]) == {target: ["changed command"]}
assert dvc.reproduce(target)[0] == stage
m.assert_called_once_with(stage)


def test_repro_when_new_deps_is_added_in_dvcfile(tmp_dir, dvc, run_copy):
Expand Down