Skip to content

Commit

Permalink
repro: Disable run-cache if --no-commit.
Browse files Browse the repository at this point in the history
As described in #4428 (comment).

Add `run_cache` argument to `Stage.save`. Set it to `False` if `no_commit`.
  • Loading branch information
daavoo committed Jan 9, 2023
1 parent 0e5674f commit a1729ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions dvc/stage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,21 @@ def compute_md5(self):
logger.debug("Computed %s md5: '%s'", self, m)
return m

def save(self, allow_missing: bool = False, merge_versioned: bool = False):
def save(
self,
allow_missing: bool = False,
merge_versioned: bool = False,
run_cache: bool = True,
):
self.save_deps(allow_missing=allow_missing)

self.save_outs(
allow_missing=allow_missing, merge_versioned=merge_versioned
)
self.md5 = self.compute_md5()

self.repo.stage_cache.save(self)
if run_cache:
self.repo.stage_cache.save(self)

def save_deps(self, allow_missing=False):
from dvc.dependency.base import DependencyDoesNotExistError
Expand Down Expand Up @@ -584,7 +590,9 @@ def run(
if not dry:
if kwargs.get("checkpoint_func", None) or no_download:
allow_missing = True
self.save(allow_missing=allow_missing)

self.save(allow_missing=allow_missing, run_cache=not no_commit)

if no_download:
self.ignore_outs()
if not no_commit:
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def test_push_pull_all(tmp_dir, scm, dvc, local_remote, key, expected):

def test_push_pull_fetch_pipeline_stages(tmp_dir, dvc, run_copy, local_remote):
tmp_dir.dvc_gen("foo", "foo")
run_copy("foo", "bar", no_commit=True, name="copy-foo-bar")
run_copy("foo", "bar", name="copy-foo-bar")

dvc.push("copy-foo-bar")
assert len(recurse_list_dir(local_remote.url)) == 1
Expand Down
3 changes: 2 additions & 1 deletion tests/func/test_repro.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,8 @@ def test_repro_no_commit(tmp_dir, dvc, copy_script, run_stage):
remove(dvc.odb.local.path)
ret = main(["repro", stage.addressing, "--no-commit"])
assert ret == 0
assert os.listdir(dvc.odb.local.path) == ["runs"]
# run-cache should be skipped if `-no-commit`.
assert not os.path.isdir(dvc.odb.local.path)


class TestReproAlreadyCached:
Expand Down

0 comments on commit a1729ac

Please sign in to comment.