Skip to content

Commit

Permalink
stage: Skip run-cache if any out has cache: false.
Browse files Browse the repository at this point in the history
As described in #4428 (comment)
  • Loading branch information
daavoo committed Dec 20, 2022
1 parent eee8627 commit dd52da5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
6 changes: 5 additions & 1 deletion dvc/stage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,11 @@ def run(
if kwargs.get("checkpoint_func", None) or no_download:
allow_missing = True

self.save(allow_missing=allow_missing, run_cache=not no_commit)
no_cache_outs = any(not out.use_cache for out in self.outs)
self.save(
allow_missing=allow_missing,
run_cache=not no_commit and not no_cache_outs,
)

if no_download:
self.ignore_outs()
Expand Down
19 changes: 0 additions & 19 deletions dvc/stage/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,6 @@ def _cache_type_copy(self):
finally:
self.repo.odb.local.cache_types = cache_types

def _uncached_outs(self, stage, cache):
# NOTE: using temporary stage to avoid accidentally modifying original
# stage and to workaround `commit/checkout` not working for uncached
# outputs.
cached_stage = self._create_stage(cache, wdir=stage.wdir)

outs_no_cache = [
out.def_path for out in stage.outs if not out.use_cache
]

# NOTE: using copy link to make it look like a git-tracked file
with self._cache_type_copy():
for out in cached_stage.outs:
if out.def_path in outs_no_cache:
yield out

def save(self, stage):
from .serialize import to_single_stage_lockfile

Expand All @@ -159,9 +143,6 @@ def save(self, stage):
existing_cache = self._load_cache(cache_key, cache_value)
cache = existing_cache or cache

for out in self._uncached_outs(stage, cache):
out.commit()

if existing_cache:
return

Expand Down
11 changes: 5 additions & 6 deletions tests/func/test_run_cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from dvc.dvcfile import PIPELINE_LOCK
from dvc.utils import relpath
from dvc.utils.fs import remove


Expand Down Expand Up @@ -65,16 +64,16 @@ def test_do_not_save_on_no_exec_and_dry(tmp_dir, dvc, run_copy):
assert not dvc.stage_cache._load(stage)


def test_uncached_outs_are_cached(tmp_dir, dvc, run_copy):
def test_no_cache_outs_deactivate_run_cache(tmp_dir, dvc):
tmp_dir.gen("foo", "foo")
stage = dvc.run(
dvc.run(
deps=["foo"],
cmd="cp foo bar",
cmd="cp foo bar && cp foo goo",
outs=["goo"],
outs_no_cache=["bar"],
name="copy-foo-bar",
)
stage.outs[0].hash_info = stage.outs[0].get_hash()
assert os.path.exists(relpath(stage.outs[0].cache_path))
assert not os.path.isdir(dvc.stage_cache.cache_dir)


def test_memory_for_multiple_runs_of_same_stage(
Expand Down

0 comments on commit dd52da5

Please sign in to comment.