Skip to content

Commit

Permalink
wrap cache warnings to suppress errors (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Berenbaum authored Aug 1, 2023
1 parent 72b9125 commit 36e8c4c
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions src/dvclive/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,35 +446,36 @@ def log_artifact(
)

def cache(self, path):
if self._inside_dvc_exp:
msg = f"Skipping dvc add {path} because `dvc exp run` is running."
path_stage = None
for stage in self._dvc_repo.index.stages:
for out in stage.outs:
if out.fspath == str(Path(path).absolute()):
path_stage = stage
break
if not path_stage:
msg += (
"\nTo track it automatically during `dvc exp run`, "
"add it as an output of the pipeline stage."
)
logger.warning(msg)
elif path_stage.cmd:
msg += "\nIt is already being tracked automatically."
logger.info(msg)
else:
msg += (
"\nTo track it automatically during `dvc exp run`:"
f"\n1. Run `dvc exp remove {path_stage.addressing}` "
"to stop tracking it outside the pipeline."
"\n2. Add it as an output of the pipeline stage."
)
logger.warning(msg)
return

try:
if self._inside_dvc_exp:
msg = f"Skipping dvc add {path} because `dvc exp run` is running."
path_stage = None
for stage in self._dvc_repo.index.stages:
for out in stage.outs:
if out.fspath == str(Path(path).absolute()):
path_stage = stage
break
if not path_stage:
msg += (
"\nTo track it automatically during `dvc exp run`, "
"add it as an output of the pipeline stage."
)
logger.warning(msg)
elif path_stage.cmd:
msg += "\nIt is already being tracked automatically."
logger.info(msg)
else:
msg += (
"\nTo track it automatically during `dvc exp run`:"
f"\n1. Run `dvc exp remove {path_stage.addressing}` "
"to stop tracking it outside the pipeline."
"\n2. Add it as an output of the pipeline stage."
)
logger.warning(msg)
return

stage = self._dvc_repo.add(str(path))

except Exception as e: # noqa: BLE001
logger.warning(f"Failed to dvc add {path}: {e}")
return
Expand Down

0 comments on commit 36e8c4c

Please sign in to comment.