Exemplo n.º 1
0
    def run(self):
        try:
            metrics = self.repo.metrics.show(
                self.args.targets,
                all_branches=self.args.all_branches,
                all_tags=self.args.all_tags,
                all_commits=self.args.all_commits,
                recursive=self.args.recursive,
            )
        except DvcException:
            logger.exception("")
            return 1

        if self.args.show_json:
            import json

            logger.info(json.dumps(metrics))
        else:
            from dvc.compare import show_metrics

            # When `metrics` contains a `None` key, it means that some files
            # specified as `targets` in `repo.metrics.show` didn't contain any
            # metrics.
            missing = metrics.pop(None, None)
            if missing:
                raise BadMetricError(missing)

            show_metrics(
                metrics,
                markdown=self.args.show_md,
                all_branches=self.args.all_branches,
                all_tags=self.args.all_tags,
                all_commits=self.args.all_commits,
                precision=self.args.precision or DEFAULT_PRECISION,
                round_digits=True,
            )

        return 0
Exemplo n.º 2
0
def show(
    self,
    path=None,
    typ=None,
    xpath=None,
    all_branches=False,
    all_tags=False,
    recursive=False,
):
    res = {}

    for branch in self.brancher(all_branches=all_branches, all_tags=all_tags):
        entries = _collect_metrics(self, path, recursive, typ, xpath, branch)
        metrics = _read_metrics(self, entries, branch)
        if metrics:
            res[branch] = metrics

    if not res:
        if path:
            raise BadMetricError(path)
        raise NoMetricsError()

    return res
Exemplo n.º 3
0
def show_metrics(metrics,
                 all_branches=False,
                 all_tags=False,
                 all_commits=False):
    """
    Args:
        metrics (list): Where each element is either a `list`
            if an xpath was specified, otherwise a `str`
    """
    # When `metrics` contains a `None` key, it means that some files
    # specified as `targets` in `repo.metrics.show` didn't contain any metrics.
    missing = metrics.pop(None, None)

    for branch, val in metrics.items():
        if all_branches or all_tags or all_commits:
            logger.info("{branch}:".format(branch=branch))

        for fname, metric in val.items():
            if isinstance(metric, dict):
                lines = list(metric.values())
            elif isinstance(metric, list):
                lines = metric
            else:
                lines = metric.splitlines()

            if len(lines) > 1:
                logger.info("\t{fname}:".format(fname=fname))

                for line in lines:
                    logger.info("\t\t{content}".format(content=line))

            else:
                logger.info("\t{}: {}".format(fname, metric))

    if missing:
        raise BadMetricError(missing)