def fill_from_lock(stage, lock_data=None): """Fill values for params, checksums for outs and deps from lock.""" if not lock_data: return assert isinstance(lock_data, dict) items = chain( ((StageParams.PARAM_DEPS, dep) for dep in stage.deps), ((StageParams.PARAM_OUTS, out) for out in stage.outs), ) checksums = { key: {item["path"]: item for item in lock_data.get(key, {})} for key in [StageParams.PARAM_DEPS, StageParams.PARAM_OUTS] } for key, item in items: path = item.def_path if isinstance(item, dependency.ParamsDependency): item.fill_values(get_in(lock_data, [stage.PARAM_PARAMS, path])) continue info = get_in(checksums, [key, path], {}) info = info.copy() info.pop("path", None) item.hash_info = HashInfo.from_dict(info)
def _to_dict(self, dir_info): info = {} for _entry in dir_info: entry = _entry.copy() relpath = entry.pop(self.tree.PARAM_RELPATH) info[relpath] = HashInfo.from_dict(entry) return info
def __init__( self, stage, path, info=None, fs=None, cache=True, metric=False, plot=False, persist=False, checkpoint=False, live=False, desc=None, isexec=False, ): self._validate_output_path(path, stage) # This output (and dependency) objects have too many paths/urls # here is a list and comments: # # .def_path - path from definition in DVC file # .path_info - PathInfo/URLInfo structured resolved path # .fspath - local only, resolved # .__str__ - for presentation purposes, def_path/relpath # # By resolved path, which contains actual location, # should be absolute and don't contain remote:// refs. self.stage = stage self.repo = stage.repo if stage else None self.def_path = path self.hash_info = HashInfo.from_dict(info) if fs: self.fs = fs else: self.fs = self.FS_CLS(self.repo, {}) self.use_cache = False if self.IS_DEPENDENCY else cache self.metric = False if self.IS_DEPENDENCY else metric self.plot = False if self.IS_DEPENDENCY else plot self.persist = persist self.checkpoint = checkpoint self.live = live self.desc = desc self.path_info = self._parse_path(fs, path) if self.use_cache and self.odb is None: raise RemoteCacheRequiredError(self.path_info) self.obj = None self.isexec = False if self.IS_DEPENDENCY else isexec try: self.git_tracked_files = list( self.repo.scm.backends.backends["dulwich"]().repo.open_index()) self.git_tracked_files = [ os.path.abspath(each.decode("utf-8")) for each in self.git_tracked_files ] except (SCMError, AttributeError, NoIndexPresent): self.git_tracked_files = []
def from_list(cls, lst): from dvc.hash_info import HashInfo tree = cls(None, None, None) for _entry in lst: entry = _entry.copy() relpath = entry.pop(cls.PARAM_RELPATH) parts = tuple(relpath.split(posixpath.sep)) hash_info = HashInfo.from_dict(entry) tree.add(parts, None, hash_info) return tree
def __init__( self, stage, path, info=None, tree=None, cache=True, metric=False, plot=False, persist=False, checkpoint=False, live=False, desc=None, isexec=False, ): self._validate_output_path(path, stage) # This output (and dependency) objects have too many paths/urls # here is a list and comments: # # .def_path - path from definition in stage file # .path_info - PathInfo/URLInfo structured resolved path # .fspath - local only, resolved # .__str__ - for presentation purposes, def_path/relpath # # By resolved path, which contains actual location, # should be absolute and don't contain remote:// refs. self.stage = stage self.repo = stage.repo if stage else None self.def_path = path self.hash_info = HashInfo.from_dict(info) if tree: self.tree = tree else: self.tree = self.TREE_CLS(self.repo, {}) self.use_cache = False if self.IS_DEPENDENCY else cache self.metric = False if self.IS_DEPENDENCY else metric self.plot = False if self.IS_DEPENDENCY else plot self.persist = persist self.checkpoint = checkpoint self.live = live self.desc = desc self.path_info = self._parse_path(tree, path) if self.use_cache and self.cache is None: raise RemoteCacheRequiredError(self.path_info) self.isexec = False if self.IS_DEPENDENCY else isexec