[misc] minor output tuning.
This commit is contained in:
@ -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())
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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.')
|
||||
raise RuntimeError('I cannot be verbose and quiet at the same time.')
|
||||
|
||||
Reference in New Issue
Block a user