From 34aa357fd32fae66662d4d0b5a42186ebacf2073 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Thu, 25 May 2017 19:49:05 +0200 Subject: [PATCH] [misc] minor output tuning. --- bonobo/ext/console.py | 15 ++++++++++----- bonobo/nodes/basics.py | 11 ++++++++++- bonobo/settings.py | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/bonobo/ext/console.py b/bonobo/ext/console.py index e15453b..d454bcd 100644 --- a/bonobo/ext/console.py +++ b/bonobo/ext/console.py @@ -21,16 +21,22 @@ class ConsoleOutputPlugin(Plugin): def initialize(self): self.prefix = '' + self.counter = 0 + self._append_cache = '' def _write(self, graph_context, rewind): if settings.PROFILE: - append = ( - ('Memory', '{0:.2f} Mb'.format(memory_usage())), - # ('Total time', '{0} s'.format(execution_time(harness))), - ) + if self.counter % 10 and self._append_cache: + append = self._append_cache + else: + self._append_cache = append = ( + ('Memory', '{0:.2f} Mb'.format(memory_usage())), + # ('Total time', '{0} s'.format(execution_time(harness))), + ) else: append = () self.write(graph_context, prefix=self.prefix, append=append, rewind=rewind) + self.counter += 1 def run(self): if sys.stdout.isatty(): @@ -81,7 +87,6 @@ class ConsoleOutputPlugin(Plugin): print(MOVE_CURSOR_UP(t_cnt + 2)) -@functools.lru_cache(1) def memory_usage(): import os, psutil process = psutil.Process(os.getpid()) diff --git a/bonobo/nodes/basics.py b/bonobo/nodes/basics.py index 5ce550c..bbf6ab5 100644 --- a/bonobo/nodes/basics.py +++ b/bonobo/nodes/basics.py @@ -4,6 +4,7 @@ from pprint import pprint as _pprint import itertools from colorama import Fore, Style +from bonobo import settings from bonobo.config import Configurable, Option from bonobo.config.processors import ContextProcessor from bonobo.structs.bags import Bag @@ -72,8 +73,16 @@ def _count_counter(self, context): class PrettyPrinter(Configurable): def call(self, *args, **kwargs): + formater = self._format_quiet if settings.QUIET else self._format_console + for i, (item, value) in enumerate(itertools.chain(enumerate(args), kwargs.items())): - print(' ' if i else '•', item, '=', str(value).strip().replace('\n', '\n' + CLEAR_EOL), CLEAR_EOL) + print(formater(i, item, value)) + + def _format_quiet(self, i, item, value): + return ' '.join(((' ' if i else '-'), str(item), ':', str(value).strip())) + + def _format_console(self, i, item, value): + return ' '.join(((' ' if i else '•'), str(item), '=', str(value).strip().replace('\n', '\n' + CLEAR_EOL), CLEAR_EOL)) pprint = Tee(_pprint) diff --git a/bonobo/settings.py b/bonobo/settings.py index 9f0fbf6..d956b2c 100644 --- a/bonobo/settings.py +++ b/bonobo/settings.py @@ -21,4 +21,4 @@ QUIET = to_bool(os.environ.get('BONOBO_QUIET', 'f')) def check(): if DEBUG and QUIET: - raise RuntimeError('I cannot be verbose and quiet at the same time.') \ No newline at end of file + raise RuntimeError('I cannot be verbose and quiet at the same time.')