mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 07:18:27 +01:00
tree: get_hash: accept explicit hash name (#5452)
This commit is contained in:
+1
-1
@@ -28,7 +28,7 @@ def get_url(path, repo=None, rev=None, remote=None):
|
||||
raise OutputNotFoundError(path, repo)
|
||||
|
||||
cloud = metadata.repo.cloud
|
||||
hash_info = _repo.repo_tree.get_hash(path_info)
|
||||
hash_info = _repo.repo_tree.get_hash(path_info, "md5")
|
||||
return cloud.get_url_for(remote, checksum=hash_info.value)
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ def _changed(path_info, tree, obj, cache):
|
||||
return True
|
||||
|
||||
try:
|
||||
actual = tree.get_hash(path_info)
|
||||
actual = tree.get_hash(path_info, obj.hash_info.name)
|
||||
except FileNotFoundError:
|
||||
logger.debug("'%s' doesn't exist.", path_info)
|
||||
return True
|
||||
@@ -55,7 +55,7 @@ def _remove(path_info, tree, cache, force=False):
|
||||
tree.remove(path_info)
|
||||
return
|
||||
|
||||
current = tree.get_hash(path_info)
|
||||
current = tree.get_hash(path_info, tree.PARAM_CHECKSUM)
|
||||
try:
|
||||
obj = load(cache, current)
|
||||
check(cache, obj)
|
||||
|
||||
@@ -49,7 +49,9 @@ class RepoDependency(LocalDependency):
|
||||
def _get_hash(self, locked=True):
|
||||
with self._make_repo(locked=locked) as repo:
|
||||
path_info = PathInfo(repo.root_dir) / self.def_path
|
||||
return repo.repo_tree.get_hash(path_info, follow_subrepos=False)
|
||||
return repo.repo_tree.get_hash(
|
||||
path_info, "md5", follow_subrepos=False
|
||||
)
|
||||
|
||||
def workspace_status(self):
|
||||
current = self._get_hash(locked=True)
|
||||
|
||||
+4
-21
@@ -19,19 +19,6 @@ class ObjectFormatError(ObjectError):
|
||||
pass
|
||||
|
||||
|
||||
def _get_hash(path_info, tree, name, **kwargs):
|
||||
if tree.PARAM_CHECKSUM == name:
|
||||
return tree.get_hash(path_info, **kwargs)
|
||||
|
||||
if name == "md5":
|
||||
from dvc.hash_info import HashInfo
|
||||
from dvc.utils import file_md5
|
||||
|
||||
return HashInfo("md5", file_md5(path_info, tree, **kwargs))
|
||||
|
||||
raise AssertionError(f"unsupported hash '{name}'")
|
||||
|
||||
|
||||
class HashFile:
|
||||
def __init__(self, path_info, tree, hash_info):
|
||||
self.path_info = path_info
|
||||
@@ -48,7 +35,7 @@ class HashFile:
|
||||
return bool(self.hash_info)
|
||||
|
||||
def check(self, odb):
|
||||
actual = _get_hash(self.path_info, self.tree, odb.tree.PARAM_CHECKSUM)
|
||||
actual = self.tree.get_hash(self.path_info, odb.tree.PARAM_CHECKSUM)
|
||||
|
||||
logger.trace(
|
||||
"cache '%s' expected '%s' actual '%s'",
|
||||
@@ -76,9 +63,7 @@ class File(HashFile):
|
||||
|
||||
@classmethod
|
||||
def stage(cls, odb, path_info, tree, **kwargs):
|
||||
hash_info = _get_hash(
|
||||
path_info, tree, odb.tree.PARAM_CHECKSUM, **kwargs
|
||||
)
|
||||
hash_info = tree.get_hash(path_info, odb.tree.PARAM_CHECKSUM, **kwargs)
|
||||
raw = odb.get(hash_info)
|
||||
obj = cls(raw.path_info, raw.tree, hash_info)
|
||||
obj.src = HashFile(path_info, tree, hash_info)
|
||||
@@ -128,7 +113,7 @@ class Tree(HashFile):
|
||||
with tree.open(path_info, "rb") as fobj:
|
||||
odb.tree.upload_fobj(fobj, tmp_info)
|
||||
|
||||
hash_info = _get_hash(tmp_info, odb.tree, odb.tree.PARAM_CHECKSUM)
|
||||
hash_info = odb.tree.get_hash(tmp_info, odb.tree.PARAM_CHECKSUM)
|
||||
hash_info.value += odb.tree.CHECKSUM_DIR_SUFFIX
|
||||
hash_info.dir_info = dir_info
|
||||
hash_info.nfiles = dir_info.nfiles
|
||||
@@ -139,9 +124,7 @@ class Tree(HashFile):
|
||||
|
||||
@classmethod
|
||||
def stage(cls, odb, path_info, tree, **kwargs):
|
||||
hash_info = _get_hash(
|
||||
path_info, tree, odb.tree.PARAM_CHECKSUM, **kwargs
|
||||
)
|
||||
hash_info = tree.get_hash(path_info, odb.tree.PARAM_CHECKSUM, **kwargs)
|
||||
hi = cls.save_dir_info(odb, hash_info.dir_info, hash_info)
|
||||
hi.size = hash_info.size
|
||||
raw = odb.get(hi)
|
||||
|
||||
+1
-1
@@ -195,7 +195,7 @@ class BaseOutput:
|
||||
|
||||
def get_hash(self):
|
||||
if not self.use_cache:
|
||||
return self.tree.get_hash(self.path_info)
|
||||
return self.tree.get_hash(self.path_info, self.tree.PARAM_CHECKSUM)
|
||||
return objects.stage(self.cache, self.path_info, self.tree).hash_info
|
||||
|
||||
@property
|
||||
|
||||
+4
-2
@@ -127,7 +127,9 @@ def _output_paths(repo, repo_tree, targets):
|
||||
|
||||
def _to_checksum(output):
|
||||
if on_working_tree:
|
||||
return repo.cache.local.tree.get_hash(output.path_info).value
|
||||
return repo.cache.local.tree.get_hash(
|
||||
output.path_info, "md5"
|
||||
).value
|
||||
return output.hash_info.value
|
||||
|
||||
for stage in repo.stages:
|
||||
@@ -155,7 +157,7 @@ def _dir_output_paths(repo_tree, output, targets=None):
|
||||
if targets is None or any(
|
||||
fname.isin_or_eq(target) for target in targets
|
||||
):
|
||||
yield str(fname), repo_tree.get_file_hash(fname).value
|
||||
yield str(fname), repo_tree.get_file_hash(fname, "md5").value
|
||||
except NoRemoteError:
|
||||
logger.warning("dir cache entry for '%s' is missing", output)
|
||||
|
||||
|
||||
+2
-1
@@ -188,7 +188,8 @@ class AzureTree(BaseTree):
|
||||
properties = blob_client.get_blob_properties()
|
||||
return properties.size
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
return HashInfo(self.PARAM_CHECKSUM, self.get_etag(path_info))
|
||||
|
||||
def _upload_fobj(self, fobj, to_info):
|
||||
|
||||
+19
-16
@@ -248,7 +248,7 @@ class BaseTree:
|
||||
return hash_.endswith(cls.CHECKSUM_DIR_SUFFIX)
|
||||
|
||||
@use_state
|
||||
def get_hash(self, path_info, **kwargs):
|
||||
def get_hash(self, path_info, name, **kwargs):
|
||||
assert path_info and (
|
||||
isinstance(path_info, str) or path_info.scheme == self.scheme
|
||||
)
|
||||
@@ -280,40 +280,42 @@ class BaseTree:
|
||||
|
||||
# NOTE: loading the tree will restore hash_info.dir_info
|
||||
Tree.load(self.cache, hash_info)
|
||||
assert hash_info.name == name
|
||||
return hash_info
|
||||
|
||||
if self.isdir(path_info):
|
||||
hash_info = self.get_dir_hash(path_info, **kwargs)
|
||||
hash_info = self.get_dir_hash(path_info, name, **kwargs)
|
||||
else:
|
||||
hash_info = self.get_file_hash(path_info)
|
||||
hash_info = self.get_file_hash(path_info, name)
|
||||
|
||||
if hash_info and self.exists(path_info):
|
||||
self.state.save(path_info, hash_info)
|
||||
|
||||
return hash_info
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
raise NotImplementedError
|
||||
|
||||
def _calculate_hashes(self, file_infos):
|
||||
def _calculate_hashes(self, file_infos, name):
|
||||
def _get_file_hash(path_info):
|
||||
return self.get_file_hash(path_info, name)
|
||||
|
||||
with Tqdm(
|
||||
total=len(file_infos),
|
||||
unit="md5",
|
||||
desc="Computing file/dir hashes (only done once)",
|
||||
) as pbar:
|
||||
worker = pbar.wrap_fn(self.get_file_hash)
|
||||
worker = pbar.wrap_fn(_get_file_hash)
|
||||
with ThreadPoolExecutor(max_workers=self.hash_jobs) as executor:
|
||||
hash_infos = executor.map(worker, file_infos)
|
||||
return dict(zip(file_infos, hash_infos))
|
||||
|
||||
def _iter_hashes(self, path_info, **kwargs):
|
||||
if self.PARAM_CHECKSUM in self.DETAIL_FIELDS:
|
||||
def _iter_hashes(self, path_info, name, **kwargs):
|
||||
if name in self.DETAIL_FIELDS:
|
||||
for details in self.ls(path_info, recursive=True, detail=True):
|
||||
file_info = path_info.replace(path=details["name"])
|
||||
hash_info = HashInfo(
|
||||
self.PARAM_CHECKSUM,
|
||||
details[self.PARAM_CHECKSUM],
|
||||
size=details.get("size"),
|
||||
name, details[name], size=details.get("size"),
|
||||
)
|
||||
yield file_info, hash_info
|
||||
|
||||
@@ -327,13 +329,14 @@ class BaseTree:
|
||||
if not hash_info:
|
||||
file_infos.append(file_info)
|
||||
continue
|
||||
assert hash_info.name == name
|
||||
yield file_info, hash_info
|
||||
|
||||
yield from self._calculate_hashes(file_infos).items()
|
||||
yield from self._calculate_hashes(file_infos, name).items()
|
||||
|
||||
def _collect_dir(self, path_info, **kwargs):
|
||||
def _collect_dir(self, path_info, name, **kwargs):
|
||||
dir_info = DirInfo()
|
||||
for fi, hi in self._iter_hashes(path_info, **kwargs):
|
||||
for fi, hi in self._iter_hashes(path_info, name, **kwargs):
|
||||
if DvcIgnore.DVCIGNORE_FILE == fi.name:
|
||||
raise DvcIgnoreInCollectedDirError(fi.parent)
|
||||
|
||||
@@ -350,10 +353,10 @@ class BaseTree:
|
||||
return dir_info
|
||||
|
||||
@use_state
|
||||
def get_dir_hash(self, path_info, **kwargs):
|
||||
def get_dir_hash(self, path_info, name, **kwargs):
|
||||
from dvc.objects import Tree
|
||||
|
||||
dir_info = self._collect_dir(path_info, **kwargs)
|
||||
dir_info = self._collect_dir(path_info, name, **kwargs)
|
||||
hash_info = Tree.save_dir_info(self.repo.cache.local, dir_info)
|
||||
hash_info.size = dir_info.size
|
||||
hash_info.dir_info = dir_info
|
||||
|
||||
+5
-3
@@ -219,20 +219,22 @@ class DvcTree(BaseTree): # pylint:disable=abstract-method
|
||||
def isexec(self, path_info): # pylint: disable=unused-argument
|
||||
return False
|
||||
|
||||
def get_dir_hash(self, path_info, **kwargs):
|
||||
def get_dir_hash(self, path_info, name, **kwargs):
|
||||
try:
|
||||
outs = self._find_outs(path_info, strict=True)
|
||||
if len(outs) == 1 and outs[0].is_dir_checksum:
|
||||
out = outs[0]
|
||||
# other code expects us to fetch the dir at this point
|
||||
self._fetch_dir(out, **kwargs)
|
||||
assert out.hash_info.name == name
|
||||
return out.hash_info
|
||||
except OutputNotFoundError:
|
||||
pass
|
||||
|
||||
return super().get_dir_hash(path_info, **kwargs)
|
||||
return super().get_dir_hash(path_info, name, **kwargs)
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == "md5"
|
||||
outs = self._find_outs(path_info, strict=False)
|
||||
if len(outs) != 1:
|
||||
raise OutputNotFoundError
|
||||
|
||||
+1
-1
@@ -544,7 +544,7 @@ class GDriveTree(BaseTree):
|
||||
item_id = self._get_item_id(path_info)
|
||||
self.gdrive_delete_file(item_id)
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
raise NotImplementedError
|
||||
|
||||
def getsize(self, path_info):
|
||||
|
||||
+2
-1
@@ -194,10 +194,11 @@ class GSTree(BaseTree):
|
||||
to_bucket = self.gs.bucket(to_info.bucket)
|
||||
from_bucket.copy_blob(blob, to_bucket, new_name=to_info.path)
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
import base64
|
||||
import codecs
|
||||
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
bucket = path_info.bucket
|
||||
path = path_info.path
|
||||
blob = self.gs.bucket(bucket).get_blob(path)
|
||||
|
||||
+2
-1
@@ -227,7 +227,8 @@ class HDFSTree(BaseTree):
|
||||
file_info = hdfs.get_file_info(path_info.path)
|
||||
return file_info.size
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
# NOTE: pyarrow doesn't support checksum, so we need to use hadoop
|
||||
return HashInfo(
|
||||
self.PARAM_CHECKSUM,
|
||||
|
||||
+3
-1
@@ -152,7 +152,9 @@ class HTTPTree(BaseTree): # pylint:disable=abstract-method
|
||||
raise HTTPError(response.status_code, response.reason)
|
||||
return self._content_length(response)
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
|
||||
url = path_info.url
|
||||
|
||||
headers = self._head(url).headers
|
||||
|
||||
+3
-2
@@ -207,8 +207,9 @@ class LocalTree(BaseTree):
|
||||
def reflink(self, from_info, to_info):
|
||||
System.reflink(from_info, to_info)
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
hash_info = HashInfo(self.PARAM_CHECKSUM, file_md5(path_info))
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == "md5"
|
||||
hash_info = HashInfo(name, file_md5(path_info))
|
||||
|
||||
if hash_info:
|
||||
hash_info.size = os.path.getsize(path_info)
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ class MemoryTree(BaseTree):
|
||||
|
||||
return os.stat_result((0, 0, 0, 0, 0, 0, info["size"], 0, 0, 0))
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
return HashInfo(self.PARAM_CHECKSUM, file_md5(path_info, self))
|
||||
|
||||
def walk_files(self, path_info, **kwargs):
|
||||
|
||||
+6
-5
@@ -371,18 +371,18 @@ class RepoTree(BaseTree): # pylint:disable=abstract-method
|
||||
yield PathInfo(root) / fname
|
||||
|
||||
def get_dir_hash(
|
||||
self, path_info, follow_subrepos=None, **kwargs
|
||||
self, path_info, name, follow_subrepos=None, **kwargs
|
||||
): # pylint: disable=arguments-differ
|
||||
tree, dvc_tree = self._get_tree_pair(path_info)
|
||||
if tree.exists(path_info):
|
||||
return super().get_dir_hash(
|
||||
path_info, follow_subrepos=follow_subrepos, **kwargs
|
||||
path_info, name, follow_subrepos=follow_subrepos, **kwargs
|
||||
)
|
||||
if not dvc_tree:
|
||||
raise FileNotFoundError
|
||||
return dvc_tree.get_dir_hash(path_info, **kwargs)
|
||||
return dvc_tree.get_dir_hash(path_info, name, **kwargs)
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
"""Return file checksum for specified path.
|
||||
|
||||
If path_info is a DVC out, the pre-computed checksum for the file
|
||||
@@ -391,12 +391,13 @@ class RepoTree(BaseTree): # pylint:disable=abstract-method
|
||||
"""
|
||||
from dvc.utils import file_md5
|
||||
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
if not self.exists(path_info):
|
||||
raise FileNotFoundError
|
||||
_, dvc_tree = self._get_tree_pair(path_info)
|
||||
if dvc_tree and dvc_tree.exists(path_info):
|
||||
try:
|
||||
return dvc_tree.get_file_hash(path_info)
|
||||
return dvc_tree.get_file_hash(path_info, name)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return HashInfo(self.PARAM_CHECKSUM, file_md5(path_info, self))
|
||||
|
||||
+2
-1
@@ -418,7 +418,8 @@ class S3Tree(BaseTree):
|
||||
if etag != cached_etag:
|
||||
raise ETagMismatchError(etag, cached_etag)
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
with self._get_obj(path_info) as obj:
|
||||
return HashInfo(
|
||||
self.PARAM_CHECKSUM,
|
||||
|
||||
@@ -235,10 +235,11 @@ class SSHTree(BaseTree):
|
||||
with self.ssh(from_info) as ssh:
|
||||
ssh.reflink(from_info.path, to_info.path)
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
if path_info.scheme != self.scheme:
|
||||
raise NotImplementedError
|
||||
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
with self.ssh(path_info) as ssh:
|
||||
hash_info = HashInfo(self.PARAM_CHECKSUM, ssh.md5(path_info.path),)
|
||||
|
||||
|
||||
+3
-1
@@ -148,7 +148,9 @@ class WebDAVTree(BaseTree): # pylint:disable=abstract-method
|
||||
return self._client.check(path_info.path)
|
||||
|
||||
# Gets file hash 'etag'
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
|
||||
# Use webdav client info method to get etag
|
||||
etag = self._client.info(path_info.path)["etag"].strip('"')
|
||||
|
||||
|
||||
+3
-1
@@ -124,7 +124,9 @@ class WebHDFSTree(BaseTree):
|
||||
def getsize(self, path_info):
|
||||
return self.hdfs_client.status(path_info.path)["length"]
|
||||
|
||||
def get_file_hash(self, path_info):
|
||||
def get_file_hash(self, path_info, name):
|
||||
assert name == self.PARAM_CHECKSUM
|
||||
|
||||
checksum = self.hdfs_client.checksum(path_info.path)
|
||||
hash_info = HashInfo(self.PARAM_CHECKSUM, checksum["bytes"])
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ def test_dir_hash_should_be_key_order_agnostic(tmp_dir, dvc):
|
||||
with patch.object(
|
||||
BaseTree, "_collect_dir", return_value=dir_info,
|
||||
):
|
||||
hash1 = dvc.cache.local.tree.get_hash(path_info)
|
||||
hash1 = dvc.cache.local.tree.get_hash(path_info, "md5")
|
||||
|
||||
dir_info = DirInfo.from_list(
|
||||
[{"md5": "1", "relpath": "1"}, {"md5": "2", "relpath": "2"}]
|
||||
@@ -165,7 +165,7 @@ def test_dir_hash_should_be_key_order_agnostic(tmp_dir, dvc):
|
||||
with patch.object(
|
||||
BaseTree, "_collect_dir", return_value=dir_info,
|
||||
):
|
||||
hash2 = dvc.cache.local.tree.get_hash(path_info)
|
||||
hash2 = dvc.cache.local.tree.get_hash(path_info, "md5")
|
||||
|
||||
assert hash1 == hash2
|
||||
|
||||
|
||||
@@ -317,6 +317,8 @@ def test_tree_ls_with_etag(dvc, cloud):
|
||||
|
||||
for details in tree.ls(path_info / "data", recursive=True, detail=True):
|
||||
assert (
|
||||
tree.get_file_hash(path_info.replace(path=details["name"])).value
|
||||
tree.get_file_hash(
|
||||
path_info.replace(path=details["name"]), tree.PARAM_CHECKSUM
|
||||
).value
|
||||
== details[tree.PARAM_CHECKSUM]
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ def test_get_file_hash(tmp_dir, azure):
|
||||
to_info = azure
|
||||
tree.upload(PathInfo("foo"), to_info)
|
||||
assert tree.exists(to_info)
|
||||
hash_info = tree.get_file_hash(to_info)
|
||||
hash_info = tree.get_file_hash(to_info, "etag")
|
||||
assert hash_info.name == "etag"
|
||||
hash_ = hash_info.value
|
||||
assert hash_
|
||||
|
||||
@@ -98,8 +98,8 @@ def test_copy_preserve_etag_across_buckets(remote, dvc):
|
||||
|
||||
remote.tree.copy(from_info, to_info)
|
||||
|
||||
from_hash = remote.tree.get_hash(from_info)
|
||||
to_hash = another.get_hash(to_info)
|
||||
from_hash = remote.tree.get_hash(from_info, remote.tree.PARAM_CHECKSUM)
|
||||
to_hash = another.get_hash(to_info, remote.tree.PARAM_CHECKSUM)
|
||||
|
||||
assert from_hash == to_hash
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ def test_isdvc(tmp_dir, dvc):
|
||||
def test_get_hash_file(tmp_dir, dvc):
|
||||
tmp_dir.dvc_gen({"foo": "foo"})
|
||||
tree = DvcTree(dvc)
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "foo") == HashInfo(
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "foo", "md5") == HashInfo(
|
||||
"md5", "acbd18db4cc2f85cedef654fccc4a4d8",
|
||||
)
|
||||
|
||||
@@ -211,7 +211,7 @@ def test_get_hash_dir(tmp_dir, dvc, mocker):
|
||||
)
|
||||
tree = DvcTree(dvc)
|
||||
get_file_hash_spy = mocker.spy(tree, "get_file_hash")
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "dir") == HashInfo(
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "dir", "md5") == HashInfo(
|
||||
"md5", "8761c4e9acad696bee718615e23e22db.dir",
|
||||
)
|
||||
assert not get_file_hash_spy.called
|
||||
@@ -223,10 +223,10 @@ def test_get_hash_granular(tmp_dir, dvc):
|
||||
)
|
||||
tree = DvcTree(dvc)
|
||||
subdir = PathInfo(tmp_dir) / "dir" / "subdir"
|
||||
assert tree.get_hash(subdir) == HashInfo(
|
||||
assert tree.get_hash(subdir, "md5") == HashInfo(
|
||||
"md5", "af314506f1622d107e0ed3f14ec1a3b5.dir",
|
||||
)
|
||||
assert tree.get_hash(subdir / "data") == HashInfo(
|
||||
assert tree.get_hash(subdir / "data", "md5") == HashInfo(
|
||||
"md5", "8d777f385d3dfec8815d20f7496026dc",
|
||||
)
|
||||
|
||||
@@ -236,7 +236,7 @@ def test_get_hash_dirty_file(tmp_dir, dvc):
|
||||
(tmp_dir / "file").write_text("something")
|
||||
|
||||
tree = DvcTree(dvc)
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "file")
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "file", "md5")
|
||||
expected = HashInfo("md5", "8c7dd922ad47494fc02c388e12c00eac")
|
||||
assert actual == expected
|
||||
|
||||
@@ -246,7 +246,7 @@ def test_get_hash_dirty_dir(tmp_dir, dvc):
|
||||
(tmp_dir / "dir" / "baz").write_text("baz")
|
||||
|
||||
tree = DvcTree(dvc)
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "dir")
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "dir", "md5")
|
||||
expected = HashInfo("md5", "5ea40360f5b4ec688df672a4db9c17d1.dir")
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@@ -484,7 +484,7 @@ def test_get_hash_cached_file(tmp_dir, dvc, mocker):
|
||||
tmp_dir.dvc_gen({"foo": "foo"})
|
||||
tree = RepoTree(dvc)
|
||||
dvc_tree_spy = mocker.spy(tree._dvctrees[dvc.root_dir], "get_file_hash")
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "foo") == HashInfo(
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "foo", "md5") == HashInfo(
|
||||
"md5", "acbd18db4cc2f85cedef654fccc4a4d8",
|
||||
)
|
||||
assert dvc_tree_spy.called
|
||||
@@ -497,7 +497,7 @@ def test_get_hash_cached_dir(tmp_dir, dvc, mocker):
|
||||
tree = RepoTree(dvc)
|
||||
get_file_hash_spy = mocker.spy(tree, "get_file_hash")
|
||||
dvc_tree_spy = mocker.spy(tree._dvctrees[dvc.root_dir], "get_dir_hash")
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "dir") == HashInfo(
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "dir", "md5") == HashInfo(
|
||||
"md5", "8761c4e9acad696bee718615e23e22db.dir",
|
||||
)
|
||||
assert get_file_hash_spy.called
|
||||
@@ -505,7 +505,7 @@ def test_get_hash_cached_dir(tmp_dir, dvc, mocker):
|
||||
get_file_hash_spy.reset_mock()
|
||||
|
||||
shutil.rmtree(tmp_dir / "dir")
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "dir") == HashInfo(
|
||||
assert tree.get_hash(PathInfo(tmp_dir) / "dir", "md5") == HashInfo(
|
||||
"md5", "8761c4e9acad696bee718615e23e22db.dir",
|
||||
)
|
||||
assert not get_file_hash_spy.called
|
||||
@@ -519,10 +519,10 @@ def test_get_hash_cached_granular(tmp_dir, dvc, mocker):
|
||||
tree = RepoTree(dvc)
|
||||
dvc_tree_spy = mocker.spy(tree._dvctrees[dvc.root_dir], "get_file_hash")
|
||||
subdir = PathInfo(tmp_dir) / "dir" / "subdir"
|
||||
assert tree.get_hash(subdir) == HashInfo(
|
||||
assert tree.get_hash(subdir, "md5") == HashInfo(
|
||||
"md5", "af314506f1622d107e0ed3f14ec1a3b5.dir",
|
||||
)
|
||||
assert tree.get_hash(subdir / "data") == HashInfo(
|
||||
assert tree.get_hash(subdir / "data", "md5") == HashInfo(
|
||||
"md5", "8d777f385d3dfec8815d20f7496026dc",
|
||||
)
|
||||
assert dvc_tree_spy.called
|
||||
@@ -541,7 +541,7 @@ def test_get_hash_mixed_dir(tmp_dir, scm, dvc):
|
||||
tmp_dir.scm.commit("add dir")
|
||||
|
||||
tree = RepoTree(dvc)
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "dir")
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "dir", "md5")
|
||||
expected = HashInfo("md5", "e1d9e8eae5374860ae025ec84cfd85c7.dir")
|
||||
assert actual == expected
|
||||
|
||||
@@ -551,7 +551,7 @@ def test_get_hash_dirty_file(tmp_dir, dvc):
|
||||
(tmp_dir / "file").write_text("something")
|
||||
|
||||
tree = RepoTree(dvc)
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "file")
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "file", "md5")
|
||||
expected = HashInfo("md5", "8c7dd922ad47494fc02c388e12c00eac")
|
||||
assert actual == expected
|
||||
|
||||
@@ -561,7 +561,7 @@ def test_get_hash_dirty_dir(tmp_dir, dvc):
|
||||
(tmp_dir / "dir" / "baz").write_text("baz")
|
||||
|
||||
tree = RepoTree(dvc)
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "dir")
|
||||
actual = tree.get_hash(PathInfo(tmp_dir) / "dir", "md5")
|
||||
expected = HashInfo("md5", "ba75a2162ca9c29acecb7957105a0bc2.dir")
|
||||
assert actual == expected
|
||||
assert actual.dir_info.nfiles == 3
|
||||
|
||||
Reference in New Issue
Block a user