Skip to content

Commit

Permalink
plots: collect: return callable instead of data
Browse files Browse the repository at this point in the history
Related to: iterative#6923, iterative/viewer#2657
  • Loading branch information
pared authored and efiop committed Nov 22, 2021
1 parent 00e53c5 commit a9512e8
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions dvc/repo/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
import logging
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Callable, Dict, Generator, List, Optional
from functools import partial
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Generator,
List,
Optional,
)

from funcy import cached_property, first, project

Expand Down Expand Up @@ -94,9 +103,8 @@ def _collect_from_revision(

fs = RepoFileSystem(self.repo)
plots = _collect_plots(self.repo, targets, revision, recursive)
res = {}
res: Dict[str, Any] = {}
for fs_path, rev_props in plots.items():

if fs.isdir(fs_path):
plot_files = []
for pi in fs.find(fs_path):
Expand All @@ -110,12 +118,15 @@ def _collect_from_revision(
joined_props = {**rev_props, **props}
res[repo_path] = {"props": joined_props}
res[repo_path].update(
parse(
fs,
path,
props=joined_props,
onerror=onerror,
)
{
"data_source": partial(
parse,
fs,
path,
props=joined_props,
onerror=onerror,
)
}
)
return res

Expand All @@ -130,13 +141,20 @@ def show(
if onerror is None:
onerror = onerror_collect

data: Dict[str, Dict] = {}
for rev_data in self.collect(
result: Dict[str, Dict] = {}
for data in self.collect(
targets, revs, recursive, onerror=onerror, props=props
):
data.update(rev_data)

errored = errored_revisions(data)
assert len(data) == 1
revision_data = first(data.values())
if "data" in revision_data:
for path_data in revision_data["data"].values():
result_source = path_data.pop("data_source", None)
if result_source:
path_data.update(result_source())
result.update(data)

errored = errored_revisions(result)
if errored:
from dvc.ui import ui

Expand All @@ -145,7 +163,7 @@ def show(
f"'{', '.join(errored)}'."
)

return data
return result

def diff(self, *args, **kwargs):
from .diff import diff
Expand Down

0 comments on commit a9512e8

Please sign in to comment.