Example #1
0
    def show(
        self,
        targets: List[str] = None,
        revs=None,
        props=None,
        templates=None,
        recursive=False,
    ):
        from dvc.utils.collections import ensure_list

        data = self.collect(targets, revs, recursive)

        # If any mentioned plot doesn't have any data then that's an error
        for target in ensure_list(targets):
            rpath = relpath(target, self.repo.root_dir)
            if not any("data" in rev_data[key] for rev_data in data.values()
                       for key, d in rev_data.items() if rpath in key):
                raise MetricDoesNotExistError([target])

        # No data at all is a special error with a special message
        if not data:
            raise NoMetricsFoundError("plots", "--plots/--plots-no-cache")

        if templates is None:
            templates = self.templates
        return self.render(data, revs, props, templates)
Example #2
0
def show(
    repo,
    targets=None,
    all_branches=False,
    all_tags=False,
    recursive=False,
    revs=None,
    all_commits=False,
):
    res = {}
    metrics_found = False

    for rev in repo.brancher(
            revs=revs,
            all_branches=all_branches,
            all_tags=all_tags,
            all_commits=all_commits,
    ):
        metrics = _collect_metrics(repo, targets, rev, recursive)

        if not metrics_found and metrics:
            metrics_found = True

        vals = _read_metrics(repo, metrics, rev)

        if vals:
            res[rev] = vals

    if not res:
        if metrics_found:
            raise NoMetricsParsedError("metrics")
        elif targets:
            raise MetricDoesNotExistError(targets)
        else:
            raise NoMetricsFoundError("metrics", "-m/-M")

    # Hide workspace metrics if they are the same as in the active branch
    try:
        active_branch = repo.scm.active_branch()
    except (TypeError, SCMError):
        # TypeError - detached head
        # SCMError - no repo case
        pass
    else:
        if res.get("workspace") == res.get(active_branch):
            res.pop("workspace", None)

    return res
Example #3
0
    def show(self, target: str, revs: List[str] = None):
        if revs:
            revs = ["workspace", *revs]

        if not os.path.exists(target):
            raise MetricDoesNotExistError([target])

        metrics_path = target + ".json"

        metrics = None
        with contextlib.suppress(MetricsError):
            metrics = self.repo.metrics.show(targets=[metrics_path])

        plots = self.repo.plots.show(target, recursive=True, revs=revs)

        return metrics, plots
Example #4
0
    def show(self, targets=None, revs=None, props=None, templates=None):

        data = self.collect(targets, revs)

        # If any mentioned plot doesn't have any data then that's an error
        targets = [targets] if isinstance(targets, str) else targets or []
        for target in targets:
            rpath = relpath(target, self.repo.root_dir)
            if not any("data" in d[rpath] for d in data.values()):
                raise MetricDoesNotExistError([target])

        # No data at all is a special error with a special message
        if not data:
            raise NoMetricsFoundError("plots", "--plots/--plots-no-cache")

        if templates is None:
            templates = self.templates
        return self.render(data, revs, props, templates)