diff --git a/dvc/output/base.py b/dvc/output/base.py index 88a0ba2856..0a65569ed6 100644 --- a/dvc/output/base.py +++ b/dvc/output/base.py @@ -143,14 +143,14 @@ def sep(self): @property def checksum_type(self): - for t in self.remote.get_checksum_type_list(): + for t in self.remote.checksum_types(): if t in self.info: return t return None @property def checksum(self): - for t in self.remote.get_checksum_type_list(): + for t in self.remote.checksum_types(): info = self.info.get(t) if info: return info diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 5eb6acc1a0..a923b586b0 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -153,10 +153,10 @@ def group(self, name): def cache(self): return getattr(self.repo.cache, self.scheme) - def get_checksum_type_list(self): + def checksum_types(self): return [self.PARAM_CHECKSUM] - def get_prefer_checksum_type(self): + def checksum_type(self): return self.PARAM_CHECKSUM def get_file_checksum(self, path_info): @@ -186,7 +186,7 @@ def _collect_dir(self, path_info): dir_info.append( { self.PARAM_RELPATH: relpath, - self.get_prefer_checksum_type(): checksum, + self.checksum_type(): checksum, } ) @@ -201,8 +201,8 @@ def get_dir_checksum(self, path_info): if self.cache.changed_cache_file(checksum): self.cache.move(from_info, to_info) - self.state.save(path_info, checksum, self.get_prefer_checksum_type()) - self.state.save(to_info, checksum, self.get_prefer_checksum_type()) + self.state.save(path_info, checksum, self.checksum_type()) + self.state.save(to_info, checksum, self.checksum_type()) return checksum @@ -271,7 +271,7 @@ def get_checksum(self, path_info, checksum_type=None): return None if checksum_type is None: - checksum_type = self.get_prefer_checksum_type() + checksum_type = self.checksum_type() checksum = self.state.get(path_info, checksum_type) if checksum: return checksum @@ -290,7 +290,7 @@ def save_info(self, path_info, checksum_type=None): assert path_info["scheme"] == self.scheme return { checksum_type - or self.get_prefer_checksum_type(): self.get_checksum( + or self.checksum_type(): self.get_checksum( path_info, checksum_type ) } @@ -305,7 +305,7 @@ def changed_checksum(self, path_info, checksum_info, addition_check=None): return True types = set(checksum_info.keys()) - supported_types = set(self.get_checksum_type_list()) + supported_types = set(self.checksum_types()) intersection = supported_types.intersection(types) if not supported_types.intersection(types): logger.debug( @@ -390,8 +390,8 @@ def _save_file(self, path_info, checksum, save_link=True): # we need to update path and cache, since in case of reflink, # or copy cache type moving original file results in updates on # next executed command, which causes md5 recalculation - self.state.save(path_info, checksum, self.get_prefer_checksum_type()) - self.state.save(cache_info, checksum, self.get_prefer_checksum_type()) + self.state.save(path_info, checksum, self.checksum_type()) + self.state.save(cache_info, checksum, self.checksum_type()) def _save_dir(self, path_info, checksum): cache_info = self.checksum_to_path_info(checksum) @@ -399,7 +399,7 @@ def _save_dir(self, path_info, checksum): entry_info = path_info.copy() for entry in dir_info: - entry_checksum = entry[self.get_prefer_checksum_type()] + entry_checksum = entry[self.checksum_type()] entry_info["path"] = self.ospath.join( path_info["path"], entry[self.PARAM_RELPATH] ) @@ -407,8 +407,8 @@ def _save_dir(self, path_info, checksum): self._save_file(entry_info, entry_checksum, save_link=False) self.state.save_link(path_info) - self.state.save(cache_info, checksum, self.get_prefer_checksum_type()) - self.state.save(path_info, checksum, self.get_prefer_checksum_type()) + self.state.save(cache_info, checksum, self.checksum_type()) + self.state.save(path_info, checksum, self.checksum_type()) def is_empty(self, path_info): return False @@ -432,8 +432,8 @@ def save(self, path_info, checksum_info): self.scheme, ) - checksum = checksum_info[self.get_prefer_checksum_type()] - if not self.changed_cache(checksum, self.get_prefer_checksum_type()): + checksum = checksum_info[self.checksum_type()] + if not self.changed_cache(checksum, self.checksum_type()): self._checkout(path_info, checksum) return @@ -522,14 +522,13 @@ def all(self): def gc(self, cinfos): used = { - info[self.repo.cache.local.get_prefer_checksum_type()] + info[self.repo.cache.local.checksum_type()] for info in cinfos["local"] } if self.scheme != "": used |= { - info[self.get_prefer_checksum_type()] - for info in cinfos[self.scheme] + info[self.checksum_type()] for info in cinfos[self.scheme] } removed = False @@ -543,7 +542,7 @@ def gc(self, cinfos): def changed_cache_file(self, checksum, checksum_type=None): if checksum_type is None: - checksum_type = self.get_prefer_checksum_type() + checksum_type = self.checksum_type() cache_info = self.checksum_to_path_info(checksum) actual = self.get_checksum(cache_info, checksum_type) @@ -585,7 +584,7 @@ def _changed_dir_cache(self, checksum, checksum_type): def changed_cache(self, checksum, checksum_type=None): if checksum_type is None: - checksum_type = self.get_prefer_checksum_type() + checksum_type = self.checksum_type() if self.is_dir_checksum(checksum): return self._changed_dir_cache(checksum, checksum_type) return self.changed_cache_file(checksum, checksum_type) @@ -656,12 +655,12 @@ def _checkout_dir( entry_info = path_info.copy() for entry in dir_info: relpath = entry[self.PARAM_RELPATH] - checksum = entry[self.get_prefer_checksum_type()] + checksum = entry[self.checksum_type()] entry_cache_info = self.checksum_to_path_info(checksum) entry_info["url"] = self.ospath.join(path_info["url"], relpath) entry_info["path"] = self.ospath.join(path_info["path"], relpath) - entry_checksum_info = {self.get_prefer_checksum_type(): checksum} + entry_checksum_info = {self.checksum_type(): checksum} if self.changed(entry_info, entry_checksum_info): if self.exists(entry_info): self.safe_remove(entry_info, force=force) @@ -699,7 +698,7 @@ def checkout( if scheme not in ["", "local"] and scheme != self.scheme: raise NotImplementedError - checksum = checksum_info.get(self.get_prefer_checksum_type()) + checksum = checksum_info.get(self.checksum_type()) if not checksum: msg = "No checksum info for '{}'." logger.debug(msg.format(str(path_info))) diff --git a/dvc/remote/local/__init__.py b/dvc/remote/local/__init__.py index e188c6ac90..a71b4cbc5c 100644 --- a/dvc/remote/local/__init__.py +++ b/dvc/remote/local/__init__.py @@ -68,14 +68,14 @@ def __init__(self, repo, config): else: self.cache_types = copy(self.DEFAULT_CACHE_TYPES) - self._hash = [modchecksum.CHECKSUM_MD5] + self._checksum_types = [modchecksum.CHECKSUM_MD5] if repo is not None: conf = repo.config.config[Config.SECTION_CHECKSUM] hash_local = conf.get(Config.SECTION_CHECKSUM_LOCAL, None) if hash_local: - self._hash = ( + self._checksum_types = ( modchecksum.checksum_types_from_str(hash_local) - or self._hash + or self._checksum_types ) if self.cache_dir is not None and not os.path.exists(self.cache_dir): @@ -208,14 +208,14 @@ def isdir(self, path_info): def walk(self, path_info): return os.walk(path_info["path"]) - def get_checksum_type_list(self): - return self._hash + def checksum_types(self): + return self._checksum_types - def get_prefer_checksum_type(self): - return self._hash[0] + def checksum_type(self): + return self._checksum_types[0] def get_file_checksum(self, path_info): - return file_checksum(path_info["path"], self._hash[0])[0] + return file_checksum(path_info["path"], self._checksum_types[0])[0] def remove(self, path_info): if path_info["scheme"] != "local": @@ -328,7 +328,7 @@ def _group(self, checksum_infos, show_checksums=False): by_md5 = {} for info in checksum_infos: - md5 = info[self.get_prefer_checksum_type()] + md5 = info[self.checksum_type()] if show_checksums: by_md5[md5] = {"name": md5} diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index e1c7ddb08b..4aa1f945ad 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -178,7 +178,7 @@ def _collect_dir_cache( info = out.dumpd() ret = [info] r = out.remote - md5 = info[r.get_prefer_checksum_type()] + md5 = info[r.checksum_type()] if self.cache.local.changed_cache_file(md5): try: diff --git a/dvc/stage.py b/dvc/stage.py index 79d81a6f7d..c69a4aca30 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -199,14 +199,12 @@ def is_stage_file(path): return os.path.isfile(path) and Stage.is_valid_filename(path) def changed_checksum(self): - for h in self.repo.cache.local.get_checksum_type_list(): + for h in self.repo.cache.local.checksum_types(): if h in self.checksum: return self.checksum[h] != self._compute_checksum(h) return ( - self._compute_checksum( - self.repo.cache.local.get_prefer_checksum_type() - ) + self._compute_checksum(self.repo.cache.local.checksum_type()) is not None ) @@ -406,7 +404,7 @@ def is_cached(self): new_d.pop(k, None) outs = old_d.get(self.PARAM_OUTS, []) for out in outs: - out.pop(self.repo.cache.local.get_prefer_checksum_type(), None) + out.pop(self.repo.cache.local.checksum_type(), None) out.pop(RemoteS3.PARAM_CHECKSUM, None) if old_d != new_d: @@ -721,7 +719,7 @@ def save(self): for out in self.outs: out.save() - hash_type = self.repo.cache.local.get_prefer_checksum_type() + hash_type = self.repo.cache.local.checksum_type() self.checksum = {hash_type: self._compute_checksum(hash_type)} @staticmethod