def load(self): if not self.exists(): return {} with self.repo.tree.open(self.path) as fd: data = parse_stage(fd.read(), self.path) try: self.validate(data, fname=self.path) except StageFileFormatError: raise LockfileCorruptedError(self.path) return data
def test_cyclic_graph_error(tmp_dir, dvc, run_copy): tmp_dir.gen("foo", "foo") run_copy("foo", "bar", name="copy-foo-bar") run_copy("bar", "baz", name="copy-bar-baz") run_copy("baz", "foobar", name="copy-baz-foobar") with open(PIPELINE_FILE, "r") as f: data = parse_stage(f.read(), PIPELINE_FILE) data["stages"]["copy-baz-foo"] = { "cmd": "echo baz > foo", "deps": ["baz"], "outs": ["foo"], } dump_stage_file(PIPELINE_FILE, data) with pytest.raises(CyclicGraphError): dvc.reproduce(":copy-baz-foo")
def _load(self): # it raises the proper exceptions by priority: # 1. when the file doesn't exists # 2. filename is not a DVC-file # 3. path doesn't represent a regular file if not self.exists(): raise StageFileDoesNotExistError(self.path) check_dvc_filename(self.path) if not self.repo.tree.isfile(self.path): raise StageFileIsNotDvcFileError(self.path) with self.repo.tree.open(self.path) as fd: stage_text = fd.read() d = parse_stage(stage_text, self.path) self.validate(d, self.relpath) return d, stage_text
def load(repo, fname): fname, tag = Stage._get_path_tag(fname) # it raises the proper exceptions by priority: # 1. when the file doesn't exists # 2. filename is not a DVC-file # 3. path doesn't represent a regular file Stage._check_file_exists(repo, fname) Stage._check_dvc_filename(fname) Stage._check_isfile(repo, fname) with repo.tree.open(fname) as fd: stage_text = fd.read() d = parse_stage(stage_text, fname) Stage.validate(d, fname=relpath(fname)) path = os.path.abspath(fname) stage = Stage( repo=repo, path=path, wdir=os.path.abspath( os.path.join( os.path.dirname(path), d.get(Stage.PARAM_WDIR, ".") ) ), cmd=d.get(Stage.PARAM_CMD), md5=d.get(Stage.PARAM_MD5), locked=d.get(Stage.PARAM_LOCKED, False), tag=tag, always_changed=d.get(Stage.PARAM_ALWAYS_CHANGED, False), # We store stage text to apply updates to the same structure stage_text=stage_text, ) stage.deps = dependency.loadd_from( stage, d.get(Stage.PARAM_DEPS) or [] ) stage.outs = output.loadd_from(stage, d.get(Stage.PARAM_OUTS) or []) return stage