mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
experiments: fix checkpoint checkout issues (#4823)
* checkout: add option to suppress missing file warnings * experiments: fix checkpoints branch checkout issues * experiments: _get_branch_containing should not change scm checkout
This commit is contained in:
Vendored
+12
-9
@@ -537,6 +537,7 @@ class CloudCache:
|
||||
progress_callback=None,
|
||||
relink=False,
|
||||
filter_info=None,
|
||||
quiet=False,
|
||||
):
|
||||
if path_info.scheme not in ["local", self.tree.scheme]:
|
||||
raise NotImplementedError
|
||||
@@ -544,10 +545,11 @@ class CloudCache:
|
||||
failed = None
|
||||
skip = False
|
||||
if not hash_info:
|
||||
logger.warning(
|
||||
"No file hash info found for '%s'. " "It won't be created.",
|
||||
path_info,
|
||||
)
|
||||
if not quiet:
|
||||
logger.warning(
|
||||
"No file hash info found for '%s'. It won't be created.",
|
||||
path_info,
|
||||
)
|
||||
self.safe_remove(path_info, force=force)
|
||||
failed = path_info
|
||||
|
||||
@@ -558,11 +560,12 @@ class CloudCache:
|
||||
elif self.changed_cache(
|
||||
hash_info, path_info=path_info, filter_info=filter_info
|
||||
):
|
||||
logger.warning(
|
||||
"Cache '%s' not found. File '%s' won't be created.",
|
||||
hash_info,
|
||||
path_info,
|
||||
)
|
||||
if not quiet:
|
||||
logger.warning(
|
||||
"Cache '%s' not found. File '%s' won't be created.",
|
||||
hash_info,
|
||||
path_info,
|
||||
)
|
||||
self.safe_remove(path_info, force=force)
|
||||
failed = path_info
|
||||
|
||||
|
||||
@@ -330,6 +330,7 @@ class BaseOutput:
|
||||
relink=False,
|
||||
filter_info=None,
|
||||
allow_missing=False,
|
||||
**kwargs,
|
||||
):
|
||||
if not self.use_cache:
|
||||
if progress_callback:
|
||||
@@ -346,6 +347,7 @@ class BaseOutput:
|
||||
progress_callback=progress_callback,
|
||||
relink=relink,
|
||||
filter_info=filter_info,
|
||||
**kwargs,
|
||||
)
|
||||
except CheckoutError:
|
||||
if allow_missing:
|
||||
|
||||
@@ -47,6 +47,7 @@ def checkout(
|
||||
relink=False,
|
||||
recursive=False,
|
||||
allow_missing=False,
|
||||
**kwargs,
|
||||
):
|
||||
from dvc.stage.exceptions import (
|
||||
StageFileBadNameError,
|
||||
@@ -98,6 +99,7 @@ def checkout(
|
||||
relink=relink,
|
||||
filter_info=filter_info,
|
||||
allow_missing=allow_missing,
|
||||
**kwargs,
|
||||
)
|
||||
for key, items in result.items():
|
||||
stats[key].extend(_fspath_dir(path) for path in items)
|
||||
|
||||
@@ -403,7 +403,7 @@ class Experiments:
|
||||
)
|
||||
exp_rev = first(results)
|
||||
if exp_rev is not None:
|
||||
self.checkout_exp(exp_rev, allow_missing=checkpoint)
|
||||
self.checkout_exp(exp_rev)
|
||||
return results
|
||||
|
||||
def reproduce_queued(self, **kwargs):
|
||||
@@ -753,7 +753,7 @@ class Experiments:
|
||||
raise UploadError(fails)
|
||||
|
||||
@scm_locked
|
||||
def checkout_exp(self, rev, allow_missing=False):
|
||||
def checkout_exp(self, rev, **kwargs):
|
||||
"""Checkout an experiment to the user's workspace."""
|
||||
from git.exc import GitCommandError
|
||||
|
||||
@@ -762,12 +762,17 @@ class Experiments:
|
||||
baseline_rev = self._check_baseline(rev)
|
||||
self._scm_checkout(rev)
|
||||
|
||||
branch = self._get_branch_containing(rev)
|
||||
m = self.BRANCH_RE.match(branch)
|
||||
if m and m.group("checkpoint"):
|
||||
kwargs.update({"allow_missing": True, "quiet": True})
|
||||
|
||||
tmp = tempfile.NamedTemporaryFile(delete=False).name
|
||||
self.scm.repo.head.commit.diff(
|
||||
baseline_rev, patch=True, full_index=True, binary=True, output=tmp
|
||||
)
|
||||
|
||||
dirty = self.repo.scm.is_dirty()
|
||||
dirty = self.repo.scm.is_dirty(untracked_files=True)
|
||||
if dirty:
|
||||
logger.debug("Stashing workspace changes.")
|
||||
self.repo.scm.repo.git.stash("push", "--include-untracked")
|
||||
@@ -787,7 +792,7 @@ class Experiments:
|
||||
self._unstash_workspace()
|
||||
|
||||
if need_checkout:
|
||||
dvc_checkout(self.repo, allow_missing=allow_missing)
|
||||
dvc_checkout(self.repo, **kwargs)
|
||||
|
||||
def _check_baseline(self, exp_rev):
|
||||
baseline_sha = self.repo.scm.get_rev()
|
||||
@@ -852,12 +857,20 @@ class Experiments:
|
||||
def _get_branch_containing(self, rev):
|
||||
from git.exc import GitCommandError
|
||||
|
||||
if self.scm.repo.head.is_detached:
|
||||
self._checkout_default_branch()
|
||||
try:
|
||||
names = self.scm.repo.git.branch(contains=rev).strip().splitlines()
|
||||
|
||||
if (
|
||||
names
|
||||
and self.scm.repo.head.is_detached
|
||||
and names[0].startswith("* (HEAD detached")
|
||||
):
|
||||
# Ignore detached head entry if it exists
|
||||
del names[0]
|
||||
|
||||
if not names:
|
||||
return None
|
||||
|
||||
if len(names) > 1:
|
||||
raise MultipleBranchError(rev)
|
||||
name = names[0]
|
||||
|
||||
@@ -168,7 +168,9 @@ class LocalExecutor(ExperimentExecutor):
|
||||
# is not polluted with the (persistent) out from an unrelated
|
||||
# experiment run
|
||||
checkpoint = kwargs.pop("checkpoint", False)
|
||||
dvc.checkout(allow_missing=checkpoint, force=checkpoint)
|
||||
dvc.checkout(
|
||||
allow_missing=checkpoint, force=checkpoint, quiet=checkpoint
|
||||
)
|
||||
stages = dvc.reproduce(
|
||||
on_unchanged=filter_pipeline,
|
||||
allow_missing=checkpoint,
|
||||
|
||||
Reference in New Issue
Block a user