| 155 | yield out |
| 156 | |
| 157 | def save(self, stage): |
| 158 | from .serialize import to_single_stage_lockfile |
| 159 | |
| 160 | if not _can_hash(stage): |
| 161 | return |
| 162 | |
| 163 | cache_key = _get_stage_hash(stage) |
| 164 | cache = to_single_stage_lockfile(stage) |
| 165 | cache_value = _get_cache_hash(cache) |
| 166 | |
| 167 | existing_cache = self._load_cache(cache_key, cache_value) |
| 168 | cache = existing_cache or cache |
| 169 | |
| 170 | for out in self._uncached_outs(stage, cache): |
| 171 | out.commit() |
| 172 | |
| 173 | if existing_cache: |
| 174 | return |
| 175 | |
| 176 | from dvc.schema import COMPILED_LOCK_FILE_STAGE_SCHEMA |
| 177 | from dvc.utils.serialize import dump_yaml |
| 178 | |
| 179 | # sanity check |
| 180 | COMPILED_LOCK_FILE_STAGE_SCHEMA(cache) |
| 181 | |
| 182 | path = self._get_cache_path(cache_key, cache_value) |
| 183 | local_fs = self.repo.cache.legacy.fs |
| 184 | parent = local_fs.parent(path) |
| 185 | self.repo.cache.legacy.makedirs(parent) |
| 186 | tmp = local_fs.join(parent, fs.utils.tmp_fname()) |
| 187 | assert os.path.exists(parent) |
| 188 | assert os.path.isdir(parent) |
| 189 | dump_yaml(tmp, cache) |
| 190 | self.repo.cache.legacy.move(tmp, path) |
| 191 | |
| 192 | def restore(self, stage, run_cache=True, pull=False, dry=False): # noqa: C901 |
| 193 | from .serialize import to_single_stage_lockfile |