From 0ad1408da7e6d63146026caab5b0fb07b7ab14e2 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 7 May 2021 14:35:35 +0300 Subject: [PATCH] plots: handle NoRemoteError for dirs (#5976) --- dvc/repo/plots/__init__.py | 18 +++++++++++++++--- tests/func/plots/test_show.py | 5 +++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index cb77580a1..4dca98210 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -51,6 +51,7 @@ class Plots: }}} Data parsing is postponed, since it's affected by props. """ + from dvc.config import NoRemoteError from dvc.fs.repo import RepoFileSystem from dvc.utils.collections import ensure_list @@ -71,10 +72,21 @@ class Plots: if fs.isdir(path_info): plot_files = [] - for pi in fs.walk_files(path_info): - plot_files.append( - (pi, relpath(pi, self.repo.root_dir)) + try: + for pi in fs.walk_files(path_info): + plot_files.append( + (pi, relpath(pi, self.repo.root_dir)) + ) + except NoRemoteError: + logger.debug( + ( + "Could not find cache for directory '%s' on " + "'%s'. Files inside will not be plotted." + ), + path_info, + rev, ) + continue else: plot_files = [ (path_info, relpath(path_info, self.repo.root_dir)) diff --git a/tests/func/plots/test_show.py b/tests/func/plots/test_show.py index 59efab818..01e5738a8 100644 --- a/tests/func/plots/test_show.py +++ b/tests/func/plots/test_show.py @@ -828,6 +828,11 @@ def test_show_dir_plots(tmp_dir, dvc, run_copy_metrics): result = dvc.plots.show(targets=[p1]) assert set(result.keys()) == {p1} + remove(dvc.odb.local.cache_dir) + remove(subdir) + with pytest.raises(NoMetricsParsedError): + dvc.plots.show() + def test_ignore_binary_file(tmp_dir, dvc, run_copy_metrics): with open("file", "wb") as fobj: