MCPcopy
hub / github.com/treeverse/dvc / save

Method save

dvc/stage/cache.py:157–190  ·  view source on GitHub ↗
(self, stage)

Source from the content-addressed store, hash-verified

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

Callers 1

test_unhashableFunction · 0.95

Calls 14

_load_cacheMethod · 0.95
_uncached_outsMethod · 0.95
_get_cache_pathMethod · 0.95
dump_yamlFunction · 0.90
_can_hashFunction · 0.85
_get_stage_hashFunction · 0.85
_get_cache_hashFunction · 0.85
parentMethod · 0.80
joinMethod · 0.80
isdirMethod · 0.80
moveMethod · 0.80
to_single_stage_lockfileFunction · 0.70

Tested by 1

test_unhashableFunction · 0.76