From abde68108b9beaec07826afb5295e5b0a52c90d5 Mon Sep 17 00:00:00 2001 From: Parthiv20 Date: Sat, 15 Jul 2017 17:27:34 +0200 Subject: [PATCH 1/3] better windows console output --- bonobo/_api.py | 14 ++++++++------ bonobo/ext/console.py | 20 +++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bonobo/_api.py b/bonobo/_api.py index ab890c6..adeaf8b 100644 --- a/bonobo/_api.py +++ b/bonobo/_api.py @@ -4,6 +4,8 @@ from bonobo.nodes import CsvReader, CsvWriter, FileReader, FileWriter, Filter, J from bonobo.strategies import create_strategy from bonobo.util.objects import get_name + + __all__ = [] @@ -21,17 +23,17 @@ def register_api_group(*args): def run(graph, strategy=None, plugins=None, services=None): """ Main entry point of bonobo. It takes a graph and creates all the necessary plumbery around to execute it. - + The only necessary argument is a :class:`Graph` instance, containing the logic you actually want to execute. - + By default, this graph will be executed using the "threadpool" strategy: each graph node will be wrapped in a thread, and executed in a loop until there is no more input to this node. - + You can provide plugins factory objects in the plugins list, this function will add the necessary plugins for interactive console execution and jupyter notebook execution if it detects correctly that it runs in this context. - + You'll probably want to provide a services dictionary mapping service names to service instances. - + :param Graph graph: The :class:`Graph` to execute. :param str strategy: The :class:`bonobo.strategies.base.Strategy` to use. :param list plugins: The list of plugins to enhance execution. @@ -71,7 +73,7 @@ register_api(create_strategy) def open_fs(fs_url=None, *args, **kwargs): """ Wraps :func:`fs.open_fs` function with a few candies. - + :param str fs_url: A filesystem URL :param parse_result: A parsed filesystem URL. :type parse_result: :class:`ParseResult` diff --git a/bonobo/ext/console.py b/bonobo/ext/console.py index acf464b..146b991 100644 --- a/bonobo/ext/console.py +++ b/bonobo/ext/console.py @@ -2,7 +2,9 @@ import io import sys from contextlib import redirect_stdout -from colorama import Style, Fore +from colorama import Style, Fore, init +init(wrap=True) + from bonobo import settings from bonobo.plugins import Plugin @@ -23,7 +25,6 @@ class IOBuffer(): finally: previous.close() - class ConsoleOutputPlugin(Plugin): """ Outputs status information to the connected stdout. Can be a TTY, with or without support for colors/cursor @@ -43,11 +44,11 @@ class ConsoleOutputPlugin(Plugin): self._stdout = sys.stdout self.stdout = IOBuffer() - self.redirect_stdout = redirect_stdout(self.stdout) + self.redirect_stdout = redirect_stdout(self.stdout if sys.platform != 'win32' else self._stdout) self.redirect_stdout.__enter__() def run(self): - if self.isatty: + if self.isatty and sys.platform != 'win32': self._write(self.context.parent, rewind=True) else: pass # not a tty @@ -60,8 +61,13 @@ class ConsoleOutputPlugin(Plugin): t_cnt = len(context) buffered = self.stdout.switch() - for line in buffered.split('\n')[:-1]: - print(line + CLEAR_EOL, file=sys.stderr) + + if sys.platform == 'win32': + for line in buffered.split('\n')[:-1]: + print(line, file=sys.stderr) + else: + for line in buffered.split('\n')[:-1]: + print(line + CLEAR_EOL, file=sys.stderr) for i in context.graph.topologically_sorted_indexes: node = context[i] @@ -76,7 +82,7 @@ class ConsoleOutputPlugin(Plugin): else: _line = ''.join( ( - ' ', Fore.BLACK, '-', ' ', node.name, name_suffix, ' ', node.get_statistics_as_string(), + ' ', Style.BRIGHT+Fore.BLACK, '-', ' ', node.name, name_suffix, ' ', node.get_statistics_as_string(), Style.RESET_ALL, ' ', ) ) From 258bd6235da7618e7bf470a1b116505ead5bda26 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Sun, 16 Jul 2017 11:19:06 +0200 Subject: [PATCH 2/3] [logging] Removes logging colors on windows for now as the codes are mis-interpreted. --- bonobo/logging.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bonobo/logging.py b/bonobo/logging.py index 3784600..1884511 100644 --- a/bonobo/logging.py +++ b/bonobo/logging.py @@ -8,6 +8,8 @@ from colorama import Fore, Style from bonobo import settings from bonobo.util.term import CLEAR_EOL +iswindows = (sys.platform == 'win32') + def get_format(): yield '{b}[%(fg)s%(levelname)s{b}][{w}' @@ -18,9 +20,9 @@ def get_format(): colors = { - 'b': Fore.BLACK, - 'w': Fore.LIGHTBLACK_EX, - 'r': Style.RESET_ALL, + 'b': '' if iswindows else Fore.BLACK, + 'w': '' if iswindows else Fore.LIGHTBLACK_EX, + 'r': '' if iswindows else Style.RESET_ALL, } format = (''.join(get_format())).format(**colors) @@ -28,7 +30,9 @@ format = (''.join(get_format())).format(**colors) class Filter(logging.Filter): def filter(self, record): record.spent = record.relativeCreated // 1000 - if record.levelname == 'DEBG': + if iswindows: + record.fg = '' + elif record.levelname == 'DEBG': record.fg = Fore.LIGHTBLACK_EX elif record.levelname == 'INFO': record.fg = Fore.LIGHTWHITE_EX @@ -46,7 +50,10 @@ class Filter(logging.Filter): class Formatter(logging.Formatter): def formatException(self, ei): tb = super().formatException(ei) - return textwrap.indent(tb, Fore.BLACK + ' | ' + Fore.WHITE) + if iswindows: + return textwrap.indent(tb, ' | ') + else: + return textwrap.indent(tb, Fore.BLACK + ' | ' + Fore.WHITE) def setup(level): From 423a75d554396512ac58ee37989a91835d8720f3 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Sun, 16 Jul 2017 11:26:48 +0200 Subject: [PATCH 3/3] [logging] Removes kill-until-eol character on windows platform. --- bonobo/logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bonobo/logging.py b/bonobo/logging.py index 1884511..071fcd3 100644 --- a/bonobo/logging.py +++ b/bonobo/logging.py @@ -16,7 +16,8 @@ def get_format(): yield '{b}][{w}'.join(('%(spent)04d', '%(name)s')) yield '{b}]' yield ' %(fg)s%(message)s{r}' - yield CLEAR_EOL + if not iswindows: + yield CLEAR_EOL colors = {