From cc3a0fb473f3ba9479f9aa3015249be33c1a4bc4 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Wed, 6 Mar 2024 21:01:59 -0800 Subject: [PATCH 1/3] fix(plots): handle empty directories --- dvc/repo/plots/__init__.py | 11 ++++++----- tests/integration/plots/test_plots.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index fe526d2891..7fcae7fd19 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -462,11 +462,12 @@ def _resolve_definitions( fs, data_path, props=plot_props | props, onerror=onerror ) # use config for parent directory with most specific definition - unpacked["data"] = { - k: v - for k, v in unpacked["data"].items() - if _closest_parent(fs, k, plot_ids_parents) == data_path - } + if unpacked.get("data"): + unpacked["data"] = { + k: v + for k, v in unpacked["data"].items() + if _closest_parent(fs, k, plot_ids_parents) == data_path + } dpath.merge(result, unpacked) elif _matches(targets, config_path, plot_id): adjusted_props = _adjust_sources(fs, plot_props, config_dir) diff --git a/tests/integration/plots/test_plots.py b/tests/integration/plots/test_plots.py index d53c5a467b..aa4286564e 100644 --- a/tests/integration/plots/test_plots.py +++ b/tests/integration/plots/test_plots.py @@ -503,6 +503,7 @@ def test_repo_with_dvclive_plots(tmp_dir, capsys, repo_with_dvclive_plots): @pytest.mark.vscode def test_nested_x_defn_collection(tmp_dir, dvc, scm, capsys): + # https://github.com/iterative/dvc/pull/10318 rel_pipeline_dir = "pipelines/data-increment" pipeline_rel_dvclive_metrics_dir = "dvclive/plots/metrics" pipeline_rel_other_logger_dir = "other/logger" @@ -634,3 +635,21 @@ def test_nested_x_defn_collection(tmp_dir, dvc, scm, capsys): {"step": 1, "Max_Leaf_Nodes": "50", "rev": "workspace"}, {"step": 2, "Max_Leaf_Nodes": "500", "rev": "workspace"}, ] + + +def test_plots_empty_directory(tmp_dir, dvc, scm, capsys): + (tmp_dir / "empty").mkdir() + + from dvc.utils.serialize import modify_yaml + + with modify_yaml("dvc.yaml") as dvcfile_content: + dvcfile_content["plots"] = [ + {"empty": {}}, + ] + + scm.add(["dvc.yaml"]) + scm.commit("commit dvc files") + + html_path, _, split_json_result = call(capsys) + assert split_json_result == {} + assert html_path == "" From c8689a58a2b4679d4982a88af845b5c24c221cb7 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Wed, 6 Mar 2024 21:45:41 -0800 Subject: [PATCH 2/3] Update tests/integration/plots/test_plots.py Co-authored-by: skshetry <18718008+skshetry@users.noreply.github.com> --- tests/integration/plots/test_plots.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration/plots/test_plots.py b/tests/integration/plots/test_plots.py index aa4286564e..813a9c7df0 100644 --- a/tests/integration/plots/test_plots.py +++ b/tests/integration/plots/test_plots.py @@ -643,9 +643,7 @@ def test_plots_empty_directory(tmp_dir, dvc, scm, capsys): from dvc.utils.serialize import modify_yaml with modify_yaml("dvc.yaml") as dvcfile_content: - dvcfile_content["plots"] = [ - {"empty": {}}, - ] + (tmp_dir / "dvc.yaml").dump({"plots": [{"empty": {}}]}) scm.add(["dvc.yaml"]) scm.commit("commit dvc files") From 330fddaaa11a0306275256736c1ed4a377729042 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Wed, 6 Mar 2024 22:46:23 -0800 Subject: [PATCH 3/3] cleanup after review --- tests/integration/plots/test_plots.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/integration/plots/test_plots.py b/tests/integration/plots/test_plots.py index 813a9c7df0..c41ec86576 100644 --- a/tests/integration/plots/test_plots.py +++ b/tests/integration/plots/test_plots.py @@ -503,7 +503,6 @@ def test_repo_with_dvclive_plots(tmp_dir, capsys, repo_with_dvclive_plots): @pytest.mark.vscode def test_nested_x_defn_collection(tmp_dir, dvc, scm, capsys): - # https://github.com/iterative/dvc/pull/10318 rel_pipeline_dir = "pipelines/data-increment" pipeline_rel_dvclive_metrics_dir = "dvclive/plots/metrics" pipeline_rel_other_logger_dir = "other/logger" @@ -639,10 +638,6 @@ def test_nested_x_defn_collection(tmp_dir, dvc, scm, capsys): def test_plots_empty_directory(tmp_dir, dvc, scm, capsys): (tmp_dir / "empty").mkdir() - - from dvc.utils.serialize import modify_yaml - - with modify_yaml("dvc.yaml") as dvcfile_content: (tmp_dir / "dvc.yaml").dump({"plots": [{"empty": {}}]}) scm.add(["dvc.yaml"])