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

run-cache: don't save always_changed stages #4719

Merged
merged 1 commit into from
Oct 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions dvc/stage/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tempfile
from contextlib import contextmanager

from funcy import first
from funcy import cached_property, first
from voluptuous import Invalid

from dvc.cache.local import _log_exceptions
Expand Down Expand Up @@ -48,7 +48,10 @@ def _get_stage_hash(stage):
class StageCache:
def __init__(self, repo):
self.repo = repo
self.cache_dir = os.path.join(repo.cache.local.cache_dir, "runs")

@cached_property
def cache_dir(self):
return os.path.join(self.repo.cache.local.cache_dir, "runs")

@property
def tree(self):
Expand Down Expand Up @@ -129,6 +132,9 @@ def _uncached_outs(self, stage, cache):
yield out

def save(self, stage):
if stage.is_callback or stage.always_changed:
return

cache_key = _get_stage_hash(stage)
if not cache_key:
return
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/stage/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

import pytest


def test_stage_cache(tmp_dir, dvc, mocker):
tmp_dir.gen("dep", "dep")
Expand Down Expand Up @@ -204,3 +206,19 @@ def _mode(path):
assert _mode(parent_cache_dir) == dir_mode
assert _mode(cache_dir) == dir_mode
assert _mode(cache_file) == file_mode


def test_always_changed(mocker):
from dvc.repo import Repo
from dvc.stage import Stage
from dvc.stage.cache import RunCacheNotFoundError, StageCache

repo = mocker.Mock(spec=Repo)
cache = StageCache(repo)
stage = Stage(repo, always_changed=True)
get_stage_hash = mocker.patch("dvc.stage.cache._get_stage_hash")
efiop marked this conversation as resolved.
Show resolved Hide resolved
assert cache.save(stage) is None
assert get_stage_hash.not_called
with pytest.raises(RunCacheNotFoundError):
cache.restore(stage)
assert get_stage_hash.not_called