diff --git a/dvc/render/utils.py b/dvc/render/utils.py index 6734ac65d..e9b93021b 100644 --- a/dvc/render/utils.py +++ b/dvc/render/utils.py @@ -1,6 +1,8 @@ import os.path from typing import Dict, List +import dpath + def get_files(data: Dict) -> List: files = set() @@ -12,38 +14,15 @@ def get_files(data: Dict) -> List: def group_by_filename(plots_data: Dict) -> List[Dict]: - # TODO use dpath.util.search once - # https://github.com/dpath-maintainers/dpath-python/issues/147 is released - # now cannot search when errors are present in data files = get_files(plots_data) grouped = [] - for file in files: - tmp: Dict = {} - for revision, revision_data in plots_data.items(): - if file in revision_data.get("data", {}): - if "data" not in tmp: - tmp[revision] = {"data": {}} - tmp[revision]["data"].update( - {file: revision_data["data"][file]} - ) - grouped.append(tmp) - + grouped.append(dpath.util.search(plots_data, ["*", "*", file])) return grouped def find_vega(repo, plots_data, target): - # TODO same as group_by_filename - grouped = group_by_filename(plots_data) - found = None - for plot_group in grouped: - files = get_files(plot_group) - assert len(files) == 1 - file = files.pop() - if file == target: - found = plot_group - break - + found = dpath.util.search(plots_data, ["*", "*", target]) from dvc.render.vega import VegaRenderer if found and VegaRenderer.matches(found): diff --git a/requirements/default.txt b/requirements/default.txt index 7fa2d2c5f..b97a691a8 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -34,7 +34,7 @@ importlib-metadata>=1.4; python_version < '3.8' flatten_dict>=0.4.1,<1 tabulate>=0.8.7 pygtrie>=2.3.2 -dpath>=2.0.1,<3 +dpath>=2.0.2,<3 shtab>=1.3.4,<2 rich>=10.0.0 dictdiffer>=0.8.1