From c10b663f3c477824b04c837e2a7a43cafe61be1f Mon Sep 17 00:00:00 2001 From: dberenbaum Date: Wed, 16 Aug 2023 11:49:20 -0400 Subject: [PATCH 1/2] log_artifact: update warning inside exp --- src/dvclive/live.py | 4 ++-- tests/test_log_artifact.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/dvclive/live.py b/src/dvclive/live.py index 758c8b63..e97f0d82 100644 --- a/src/dvclive/live.py +++ b/src/dvclive/live.py @@ -465,7 +465,7 @@ def cache(self, path): path_stage = None for stage in self._dvc_repo.index.stages: for out in stage.outs: - if out.fspath == str(Path(path).absolute()): + if out.fspath in str(Path(path).absolute()): path_stage = stage break if path_stage and path_stage.cmd: @@ -478,7 +478,7 @@ def cache(self, path): if path_stage: msg = ( f"\nTo track '{path}' automatically during `dvc exp run`:" - f"\n1. Run `dvc exp remove {path_stage.addressing}` " + f"\n1. Run `dvc remove {path_stage.addressing}` " "to stop tracking it outside the pipeline." "\n2. Add it as an output of the pipeline stage." ) diff --git a/tests/test_log_artifact.py b/tests/test_log_artifact.py index 820a144c..c5a3b997 100644 --- a/tests/test_log_artifact.py +++ b/tests/test_log_artifact.py @@ -250,7 +250,7 @@ def test_log_artifact_inside_exp(tmp_dir, mocker, dvc_repo, tracked): elif tracked == "data_source": msg = ( "\nTo track 'data' automatically during `dvc exp run`:" - "\n1. Run `dvc exp remove data.dvc` " + "\n1. Run `dvc remove data.dvc` " "to stop tracking it outside the pipeline." "\n2. Add it as an output of the pipeline stage." ) @@ -263,3 +263,24 @@ def test_log_artifact_inside_exp(tmp_dir, mocker, dvc_repo, tracked): ) logger.warning.assert_called_with(msg) spy.assert_called_once() + + +def test_log_artifact_inside_exp_subdir(tmp_dir, mocker, dvc_repo): + logger = mocker.patch("dvclive.live.logger") + subdir = tmp_dir / "subdir" + subdir.mkdir() + data = subdir / "data" + data.touch() + dvc_repo.add(subdir) + live = Live() + spy = mocker.spy(live._dvc_repo, "add") + live._inside_dvc_exp = True + live.log_artifact("subdir/data") + msg = ( + "\nTo track 'subdir/data' automatically during `dvc exp run`:" + "\n1. Run `dvc remove subdir.dvc` " + "to stop tracking it outside the pipeline." + "\n2. Add it as an output of the pipeline stage." + ) + logger.warning.assert_called_with(msg) + spy.assert_called_once() From fa05300f7950d5d79b2340008135ae8060a81e06 Mon Sep 17 00:00:00 2001 From: dberenbaum Date: Thu, 17 Aug 2023 10:26:12 -0400 Subject: [PATCH 2/2] fix test --- tests/test_log_artifact.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_log_artifact.py b/tests/test_log_artifact.py index 236a4182..5c6443ac 100644 --- a/tests/test_log_artifact.py +++ b/tests/test_log_artifact.py @@ -277,7 +277,7 @@ def test_log_artifact_inside_exp_subdir(tmp_dir, mocker, dvc_repo): live._inside_dvc_exp = True live.log_artifact("subdir/data") msg = ( - "\nTo track 'subdir/data' automatically during `dvc exp run`:" + "To track 'subdir/data' automatically during `dvc exp run`:" "\n1. Run `dvc remove subdir.dvc` " "to stop tracking it outside the pipeline." "\n2. Add it as an output of the pipeline stage."