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

Method save

dvc/repo/experiments/executor/base.py:260–337  ·  view source on GitHub ↗
(
        cls,
        info: "ExecutorInfo",
        targets: Optional[Iterable[str]] = None,
        recursive: bool = False,
        force: bool = False,
        include_untracked: Optional[list[str]] = None,
        message: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

258
259 @classmethod
260 def save(
261 cls,
262 info: "ExecutorInfo",
263 targets: Optional[Iterable[str]] = None,
264 recursive: bool = False,
265 force: bool = False,
266 include_untracked: Optional[list[str]] = None,
267 message: Optional[str] = None,
268 ) -> ExecutorResult:
269 from dvc.dvcfile import LOCK_FILE
270 from dvc.repo import Repo
271
272 exp_hash: Optional[str] = None
273 exp_ref: Optional[ExpRefInfo] = None
274
275 dvc = Repo(os.path.join(info.root_dir, info.dvc_dir))
276 old_cwd = os.getcwd()
277 if info.wdir:
278 os.chdir(os.path.join(dvc.scm.root_dir, info.wdir))
279 else:
280 os.chdir(dvc.root_dir)
281
282 include_untracked = include_untracked or []
283 include_untracked.extend(cls._get_top_level_paths(dvc))
284 # dvc repro automatically stages dvc.lock. Running redundant `git add`
285 # on it causes an error when exiting the detached head context.
286 if LOCK_FILE in dvc.scm.untracked_files():
287 include_untracked.append(LOCK_FILE)
288
289 try:
290 stages = []
291 if targets:
292 for target in targets:
293 stages.append( # noqa: PERF401
294 dvc.commit(
295 target, recursive=recursive, force=True, relink=False
296 )
297 )
298 else:
299 stages = dvc.commit([], recursive=recursive, force=True, relink=False)
300 exp_hash = cls.hash_exp(stages)
301 if include_untracked:
302 from dvc.scm import add_no_submodules
303
304 add_no_submodules(dvc.scm, include_untracked, force=True) # type: ignore[call-arg]
305
306 with cls.auto_push(dvc):
307 cls.commit(
308 dvc.scm, # type: ignore[arg-type]
309 exp_hash,
310 exp_name=info.name,
311 force=force,
312 message=message,
313 )
314
315 ref: Optional[str] = dvc.scm.get_ref(EXEC_BRANCH, follow=False)
316 exp_ref = ExpRefInfo.from_ref(ref) if ref else None
317 untracked = dvc.scm.untracked_files()

Callers

nothing calls this directly

Calls 14

closeMethod · 0.95
RepoClass · 0.90
add_no_submodulesFunction · 0.90
ExecutorResultClass · 0.85
joinMethod · 0.80
extendMethod · 0.80
_get_top_level_pathsMethod · 0.80
appendMethod · 0.80
hash_expMethod · 0.80
auto_pushMethod · 0.80
from_refMethod · 0.80
getcwdMethod · 0.45

Tested by

no test coverage detected