cmd: implement '--show-md' flag for 'dvc metrics show' (#4770) (#5161)

This commit is contained in:
Pavel Ditenbir
2020-12-30 02:17:41 +02:00
committed by GitHub
parent 6fcafc9121
commit 23811e028c
2 changed files with 49 additions and 1 deletions
+9 -1
View File
@@ -13,6 +13,7 @@ DEFAULT_PRECISION = 5
def _show_metrics(
metrics,
markdown=False,
all_branches=False,
all_tags=False,
all_commits=False,
@@ -65,7 +66,7 @@ def _show_metrics(
if missing:
raise BadMetricError(missing)
return table(header, rows, markdown=False)
return table(header, rows, markdown)
class CmdMetricsBase(CmdBase):
@@ -90,6 +91,7 @@ class CmdMetricsShow(CmdMetricsBase):
else:
table = _show_metrics(
metrics,
self.args.show_md,
self.args.all_branches,
self.args.all_tags,
self.args.all_commits,
@@ -228,6 +230,12 @@ def add_parser(subparsers, parent_parser):
default=False,
help="Show output in JSON format.",
)
metrics_show_parser.add_argument(
"--show-md",
action="store_true",
default=False,
help="Show tabulated output in the Markdown format (GFM).",
)
metrics_show_parser.add_argument(
"-R",
"--recursive",
+40
View File
@@ -19,6 +19,7 @@ def test_metrics_diff(dvc, mocker):
"-R",
"--all",
"--show-json",
"--show-md",
"--targets",
"target1",
"target2",
@@ -330,3 +331,42 @@ def test_metrics_show_precision():
Revision Path a b.ad b.bc
branch_1 metrics.json 1.0987654 1.5342673 2.9877255"""
)
def test_metrics_show_default():
assert _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},
}
},
) == textwrap.dedent(
"""\
Path diff new old
x.b — 6 5
a.d.e 1 4 3
a.b.c 1 2 1"""
)
def test_metrics_show_md():
assert _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,
) == textwrap.dedent(
"""\
| Path | diff | new | old |
|--------|--------|-------|-------|
| x.b | — | 6 | 5 |
| a.d.e | 1 | 4 | 3 |
| a.b.c | 1 | 2 | 1 |
"""
)