diff --git a/dvc/stage/__init__.py b/dvc/stage/__init__.py index cc4ef4864f3..2645d86a69f 100644 --- a/dvc/stage/__init__.py +++ b/dvc/stage/__init__.py @@ -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() diff --git a/dvc/stage/cache.py b/dvc/stage/cache.py index 4e01f547a5d..b28836e6447 100644 --- a/dvc/stage/cache.py +++ b/dvc/stage/cache.py @@ -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 @@ -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 diff --git a/tests/func/test_run_cache.py b/tests/func/test_run_cache.py index e3973342477..7666b562928 100644 --- a/tests/func/test_run_cache.py +++ b/tests/func/test_run_cache.py @@ -1,7 +1,6 @@ import os from dvc.dvcfile import PIPELINE_LOCK -from dvc.utils import relpath from dvc.utils.fs import remove @@ -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(