Exemple #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.json:
            ui.write_json(metrics, default=encode_exception)
        else:
            from dvc.compare import show_metrics

            show_metrics(
                metrics,
                markdown=self.args.markdown,
                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
Exemple #2
0
    def run(self):
        from dvc.compare import show_metrics

        if self.args.checkpoint_resume:
            if self.args.reset:
                raise InvalidArgumentError(
                    "--reset and --rev are mutually exclusive.")
            if not (self.args.queue or self.args.tmp_dir):
                raise InvalidArgumentError(
                    "--rev can only be used in conjunction with "
                    "--queue or --temp.")

        if self.args.reset:
            ui.write("Any existing checkpoints will be reset and re-run.")

        results = self.repo.experiments.run(
            name=self.args.name,
            queue=self.args.queue,
            run_all=self.args.run_all,
            jobs=self.args.jobs,
            params=self.args.set_param,
            checkpoint_resume=self.args.checkpoint_resume,
            reset=self.args.reset,
            tmp_dir=self.args.tmp_dir,
            machine=self.args.machine,
            **self._repro_kwargs,
        )

        if self.args.metrics and results:
            metrics = self.repo.metrics.show(revs=list(results))
            metrics.pop("workspace", None)
            show_metrics(metrics)

        return 0
Exemple #3
0
def test_metrics_show_md(capsys):
    show_metrics(
        {
            "metrics.yaml": {
                "x.b": {
                    "old": 5,
                    "new": 6
                },
                "a.d.e": {
                    "old": 3,
                    "new": 4,
                    "diff": 1
                },
                "a.b.c": {
                    "old": 1,
                    "new": 2,
                    "diff": 1
                },
            }
        },
        markdown=True,
    )
    out, _ = capsys.readouterr()
    assert out == textwrap.dedent("""\
        | Path   | diff   | new   | old   |
        |--------|--------|-------|-------|
        | x.b    | -      | 6     | 5     |
        | a.d.e  | 1      | 4     | 3     |
        | a.b.c  | 1      | 2     | 1     |

        """)
Exemple #4
0
def test_metrics_show_default(capsys):
    show_metrics(
        {
            "metrics.yaml": {
                "x.b": {
                    "old": 5,
                    "new": 6
                },
                "a.d.e": {
                    "old": 3,
                    "new": 4,
                    "diff": 1
                },
                "a.b.c": {
                    "old": 1,
                    "new": 2,
                    "diff": 1
                },
            }
        }, )
    out, _ = capsys.readouterr()
    assert out == textwrap.dedent("""\
        Path    diff    new    old
        x.b     -       6      5
        a.d.e   1       4      3
        a.b.c   1       2      1
        """)
Exemple #5
0
def test_metrics_show_markdown(capsys):
    show_metrics(
        metrics={
            "branch_1": {
                "data": {
                    "metrics.json": {"data": {"b": {"ad": 1, "bc": 2}, "c": 4}}
                }
            },
            "branch_2": {
                "data": {
                    "metrics.json": {"data": {"a": 1, "b": {"ad": 3, "bc": 4}}}
                }
            },
            "branch_3": {"error": YAMLFileCorruptedError("failed")},
        },
        all_branches=True,
        markdown=True,
    )
    out, _ = capsys.readouterr()
    assert out == textwrap.dedent(
        """\
        | Revision   | Path         | a   | b.ad   | b.bc   | c   |
        |------------|--------------|-----|--------|--------|-----|
        | branch_1   | metrics.json | -   | 1      | 2      | 4   |
        | branch_2   | metrics.json | 1   | 3      | 4      | -   |

        """
    )
Exemple #6
0
def test_metrics_show_default(capsys):
    show_metrics(
        metrics={
            "branch_1": {
                "data": {
                    "metrics.json": {"data": {"b": {"ad": 1, "bc": 2}, "c": 4}}
                },
                "error": Exception("Failed just a little bit"),
            },
            "branch_2": {
                "data": {
                    "metrics.json": {"data": {"a": 1, "b": {"ad": 3, "bc": 4}}}
                }
            },
        },
        all_branches=True,
    )
    out, _ = capsys.readouterr()
    assert out == textwrap.dedent(
        """\
        Revision    Path          a    b.ad    b.bc    c
        branch_1    metrics.json  -    1       2       4
        branch_2    metrics.json  1    3       4       -
        """
    )
Exemple #7
0
def test_metrics_show_mocked(mocker, markdown):
    ret = mocker.MagicMock()
    m = mocker.patch("dvc.compare.metrics_table", return_value=ret)

    show_metrics({}, markdown=markdown)

    m.assert_called_once_with(
        {},
        all_branches=False,
        all_tags=False,
        all_commits=False,
        precision=None,
        round_digits=False,
    )
    ret.render.assert_called_once_with(markdown=markdown)
Exemple #8
0
    def run(self):
        stages = self.repo.reproduce(**self._repro_kwargs)
        if len(stages) == 0:
            logger.info(CmdDataStatus.UP_TO_DATE_MSG)
        else:
            logger.info("Use `dvc push` to send your updates to "
                        "remote storage.")

        if self.args.metrics:
            from dvc.compare import show_metrics

            metrics = self.repo.metrics.show()
            show_metrics(metrics)

        return 0
Exemple #9
0
    def run(self):
        from dvc.ui import ui

        stages = self.repo.reproduce(**self._common_kwargs,
                                     **self._repro_kwargs)
        if len(stages) == 0:
            ui.write(CmdDataStatus.UP_TO_DATE_MSG)
        else:
            ui.write("Use `dvc push` to send your updates to remote storage.")

        if self.args.metrics:
            from dvc.compare import show_metrics

            metrics = self.repo.metrics.show()
            show_metrics(metrics)

        return 0
Exemple #10
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