experiments: add --no-pager option for exp show (#4345)

This commit is contained in:
Peter Rowlands (변기호)
2020-08-06 15:48:40 +09:00
committed by GitHub
parent 35dd1fda9c
commit 6bb654750a
+21 -9
View File
@@ -59,7 +59,9 @@ def _collect_rows(
item = {fname: item}
for name in names:
if name in item:
row.append(str(_round(item[name])))
value = item[name]
text = str(_round(value)) if value is not None else "-"
row.append(text)
else:
row.append("-")
@@ -88,9 +90,9 @@ def _show_experiments(all_experiments, console, precision=None):
metric_names, param_names = _collect_names(all_experiments)
table = Table()
table.add_column("Experiment")
table.add_column("Experiment", no_wrap=True)
for name in metric_names:
table.add_column(name, justify="right")
table.add_column(name, justify="right", no_wrap=True)
for name in param_names:
table.add_column(name, justify="left")
@@ -125,15 +127,19 @@ class CmdExperimentsShow(CmdBase):
all_commits=self.args.all_commits,
)
# Note: rich does not currently include a native way to force
# infinite width for use with a pager
console = Console(
file=io.StringIO(), force_terminal=True, width=9999
)
if self.args.no_pager:
console = Console()
else:
# Note: rich does not currently include a native way to force
# infinite width for use with a pager
console = Console(
file=io.StringIO(), force_terminal=True, width=9999
)
_show_experiments(all_experiments, console)
pager(console.file.getvalue())
if not self.args.no_pager:
pager(console.file.getvalue())
except DvcException:
logger.exception("failed to show experiments")
return 1
@@ -273,6 +279,12 @@ def add_parser(subparsers, parent_parser):
default=False,
help="Show metrics for all commits.",
)
experiments_show_parser.add_argument(
"--no-pager",
action="store_true",
default=False,
help="Do not pipe output into a pager.",
)
experiments_show_parser.set_defaults(func=CmdExperimentsShow)
EXPERIMENTS_CHECKOUT_HELP = "Checkout experiments."