mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-16 23:09:55 +01:00
cache: move save() to objects (#5430)
This commit is contained in:
Vendored
-4
@@ -233,10 +233,6 @@ class CloudCache:
|
||||
self.cache_type_confirmed = True
|
||||
return self.cache_types[0] == "copy"
|
||||
|
||||
@use_state
|
||||
def save(self, obj, **kwargs):
|
||||
obj.save(self, **kwargs)
|
||||
|
||||
# Override to return path as a string instead of PathInfo for clouds
|
||||
# which support string paths (see local)
|
||||
def hash_to_path(self, hash_):
|
||||
|
||||
@@ -71,7 +71,7 @@ class RepoDependency(LocalDependency):
|
||||
|
||||
def download(self, to, jobs=None):
|
||||
from dvc.checkout import checkout
|
||||
from dvc.objects import stage
|
||||
from dvc.objects import save, stage
|
||||
|
||||
cache = self.repo.cache.local
|
||||
|
||||
@@ -86,7 +86,7 @@ class RepoDependency(LocalDependency):
|
||||
jobs=jobs,
|
||||
follow_subrepos=False,
|
||||
)
|
||||
cache.save(obj, jobs=jobs)
|
||||
save(cache, obj, jobs=jobs)
|
||||
|
||||
checkout(to.path_info, to.tree, obj, cache)
|
||||
|
||||
|
||||
+4
-2
@@ -186,8 +186,6 @@ class Tree(HashFile):
|
||||
):
|
||||
entry_obj = HashFile(entry_info, self.src_tree, entry_hash)
|
||||
entry_obj.save(odb, **kwargs)
|
||||
cache_info = odb.tree.hash_to_path_info(hi.value)
|
||||
odb.tree.state.save(cache_info, hi)
|
||||
self.src_tree.state.save(self.src_path_info, hi)
|
||||
|
||||
def filter(self, odb, prefix):
|
||||
@@ -212,6 +210,10 @@ def stage(odb, path_info, tree, **kwargs):
|
||||
return File.stage(odb, path_info, tree, **kwargs)
|
||||
|
||||
|
||||
def save(odb, obj, **kwargs):
|
||||
obj.save(odb, **kwargs)
|
||||
|
||||
|
||||
def check(odb, obj):
|
||||
odb.check(obj.hash_info)
|
||||
|
||||
|
||||
+1
-1
@@ -322,7 +322,7 @@ class BaseOutput:
|
||||
obj = objects.stage(
|
||||
self.cache, filter_info or self.path_info, self.tree
|
||||
)
|
||||
self.cache.save(obj)
|
||||
objects.save(self.cache, obj)
|
||||
checkout(
|
||||
filter_info or self.path_info,
|
||||
self.tree,
|
||||
|
||||
+3
-3
@@ -81,7 +81,7 @@ def fetch(
|
||||
|
||||
def _fetch_external(self, repo_url, repo_rev, files, jobs):
|
||||
from dvc.external_repo import external_repo
|
||||
from dvc.objects import stage
|
||||
from dvc.objects import save, stage
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.scm.base import CloneError
|
||||
|
||||
@@ -117,8 +117,8 @@ def _fetch_external(self, repo_url, repo_rev, files, jobs):
|
||||
jobs=jobs,
|
||||
follow_subrepos=False,
|
||||
)
|
||||
cache.save(
|
||||
obj, jobs=jobs, download_callback=cb,
|
||||
save(
|
||||
cache, obj, jobs=jobs, download_callback=cb,
|
||||
)
|
||||
except CloneError:
|
||||
failed += 1
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
from mock import ANY, patch
|
||||
|
||||
from dvc.external_repo import CLONES, external_repo
|
||||
from dvc.objects import stage
|
||||
from dvc.objects import save, stage
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.scm.git import Git
|
||||
from dvc.tree.local import LocalTree
|
||||
@@ -206,7 +206,7 @@ def test_subrepos_are_ignored(tmp_dir, erepo_dir):
|
||||
repo.repo_tree,
|
||||
follow_subrepos=False,
|
||||
)
|
||||
repo.cache.local.save(obj)
|
||||
save(repo.cache.local, obj)
|
||||
assert set(cache_dir.glob("*/*")) == {
|
||||
cache_dir / "e1" / "d9e8eae5374860ae025ec84cfd85c7.dir",
|
||||
cache_dir / "37" / "b51d194a7513e45b56f6524f2d51f2",
|
||||
|
||||
@@ -4,7 +4,7 @@ from unittest.mock import call
|
||||
import pytest
|
||||
|
||||
from dvc.external_repo import external_repo
|
||||
from dvc.objects import stage
|
||||
from dvc.objects import save, stage
|
||||
from dvc.path_info import PathInfo
|
||||
from tests.unit.tree.test_repo import make_subrepo
|
||||
|
||||
@@ -117,8 +117,8 @@ def test_fetch_external_repo_jobs(tmp_dir, scm, mocker, dvc, local_remote):
|
||||
follow_subrepos=False,
|
||||
jobs=3,
|
||||
)
|
||||
dvc.cache.local.save(
|
||||
obj, jobs=3,
|
||||
save(
|
||||
dvc.cache.local, obj, jobs=3,
|
||||
)
|
||||
|
||||
run_jobs = tuple(spy.call_args_list[0])[1].get("jobs")
|
||||
|
||||
Reference in New Issue
Block a user