From 20350b02b2c686b05957b1b70553150d750fdd76 Mon Sep 17 00:00:00 2001 From: Peter Rowlands Date: Thu, 6 Aug 2020 14:37:10 +0900 Subject: [PATCH] experiments: add --no-pager option for `exp show` --- dvc/command/experiments.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py index ffa14a4317..34fcab00f6 100644 --- a/dvc/command/experiments.py +++ b/dvc/command/experiments.py @@ -59,7 +59,9 @@ def _extend(row, names, items): 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 @@ def run(self): 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."