diff --git a/Makefile b/Makefile index 89f16e8..14825bf 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Generated by Medikit 0.4a9 on 2017-11-01. +# Generated by Medikit 0.4a10 on 2017-11-01. # All changes will be overriden. PACKAGE ?= bonobo diff --git a/Projectfile b/Projectfile index c51ac38..3a48797 100644 --- a/Projectfile +++ b/Projectfile @@ -42,7 +42,7 @@ python.setup( python.add_requirements( 'fs >=2.0,<2.1', 'jinja2 >=2.9,<2.10', - 'mondrian >=0.2,<0.3', + 'mondrian >=0.3,<0.4', 'packaging >=16,<17', 'psutil >=5.4,<6.0', 'requests >=2.0,<3.0', diff --git a/bonobo/__init__.py b/bonobo/__init__.py index 3c15c18..0ac9bc3 100644 --- a/bonobo/__init__.py +++ b/bonobo/__init__.py @@ -9,6 +9,7 @@ import sys assert (sys.version_info >= (3, 5)), 'Python 3.5+ is required to use Bonobo.' + from bonobo._api import * from bonobo._api import __all__ from bonobo._version import __version__ diff --git a/bonobo/_api.py b/bonobo/_api.py index f1e5da5..d4dbda2 100644 --- a/bonobo/_api.py +++ b/bonobo/_api.py @@ -40,7 +40,6 @@ def run(graph, *, plugins=None, services=None, strategy=None): :param dict services: The implementations of services this graph will use. :return bonobo.execution.graph.GraphExecutionContext: """ - strategy = create_strategy(strategy) plugins = plugins or [] @@ -49,6 +48,10 @@ def run(graph, *, plugins=None, services=None, strategy=None): if not settings.QUIET.get(): # pragma: no cover if _is_interactive_console(): + import mondrian + mondrian.setup() + mondrian.setupExceptHook() + from bonobo.ext.console import ConsoleOutputPlugin if ConsoleOutputPlugin not in plugins: plugins.append(ConsoleOutputPlugin) @@ -67,7 +70,7 @@ def run(graph, *, plugins=None, services=None, strategy=None): if JupyterOutputPlugin not in plugins: plugins.append(JupyterOutputPlugin) - return strategy.execute(graph, plugins=plugins, services=services) + return create_strategy(strategy).execute(graph, plugins=plugins, services=services) def _inspect_as_graph(graph): diff --git a/bonobo/commands/__init__.py b/bonobo/commands/__init__.py index c015d78..39cfa05 100644 --- a/bonobo/commands/__init__.py +++ b/bonobo/commands/__init__.py @@ -1,11 +1,9 @@ import argparse -import traceback import logging -import mondrian +import mondrian from bonobo import settings from bonobo.commands.base import BaseCommand, BaseGraphCommand -from bonobo.util.errors import print_error def entrypoint(args=None): @@ -16,7 +14,10 @@ def entrypoint(args=None): """ - logger = mondrian.getLogger() + mondrian.setup() + mondrian.setupExceptHook() + + logger = logging.getLogger() parser = argparse.ArgumentParser() parser.add_argument('--debug', '-D', action='store_true') @@ -56,9 +57,6 @@ def entrypoint(args=None): # Get command handler, execute, rince. command = commands[parsed_args.pop('command')] + command(**parsed_args) - try: - command(**parsed_args) - except Exception as exc: - print_error(exc, traceback.format_exc()) - return 255 + return 0 diff --git a/bonobo/commands/download.py b/bonobo/commands/download.py index 9333db4..96b1c2f 100644 --- a/bonobo/commands/download.py +++ b/bonobo/commands/download.py @@ -12,7 +12,6 @@ EXAMPLES_BASE_URL = 'https://raw.githubusercontent.com/python-bonobo/bonobo/mast class DownloadCommand(BaseCommand): def handle(self, *, path, **options): - path = path.lstrip('/') if not path.startswith('examples'): raise ValueError('Download command currently supports examples only') examples_path = re.sub('^examples/', '', path) diff --git a/bonobo/commands/init.py b/bonobo/commands/init.py index e5d11d2..8c50b16 100644 --- a/bonobo/commands/init.py +++ b/bonobo/commands/init.py @@ -13,7 +13,7 @@ class InitCommand(BaseCommand): parser.add_argument('filename') parser.add_argument('--force', '-f', default=False, action='store_true') - target_group = parser.add_mutually_exclusive_group(required=True) + target_group = parser.add_mutually_exclusive_group(required=False) target_group.add_argument('--template', '-t', choices=self.TEMPLATES, default='default') target_group.add_argument('--package', '-p', action='store_true', default=False) @@ -41,11 +41,13 @@ class InitCommand(BaseCommand): import medikit.commands except ImportError as exc: raise ImportError( - 'To initialize a package, you need to install medikit (pip install --upgrade medikit).') from exc + 'To initialize a package, you need to install medikit (pip install --upgrade medikit).' + ) from exc package_name = os.path.basename(filename) - medikit.commands.handle_init(os.path.join(os.getcwd(), filename, 'Projectfile'), name=package_name, - requirements=['bonobo']) + medikit.commands.handle_init( + os.path.join(os.getcwd(), filename, 'Projectfile'), name=package_name, requirements=['bonobo'] + ) self.logger.info('Generated "{}" package with medikit.'.format(package_name)) self.create_file_from_template(template='default', filename=os.path.join(filename, package_name, '__main__.py')) diff --git a/bonobo/execution/__init__.py b/bonobo/execution/__init__.py index b8a83dd..eea436a 100644 --- a/bonobo/execution/__init__.py +++ b/bonobo/execution/__init__.py @@ -1 +1,3 @@ -from bonobo.execution.graph import GraphExecutionContext, NodeExecutionContext, PluginExecutionContext +import logging + +logger = logging.getLogger(__name__) diff --git a/bonobo/execution/base.py b/bonobo/execution/base.py index b9bce36..d469631 100644 --- a/bonobo/execution/base.py +++ b/bonobo/execution/base.py @@ -1,12 +1,17 @@ -import traceback +import logging from contextlib import contextmanager +from logging import WARNING, ERROR from time import sleep +import sys + +import mondrian + from bonobo.config import create_container from bonobo.config.processors import ContextCurrifier from bonobo.util import isconfigurabletype -from bonobo.util.errors import print_error from bonobo.util.objects import Wrapper, get_name +from bonobo.execution import logger @contextmanager @@ -14,7 +19,7 @@ def recoverable(error_handler): try: yield except Exception as exc: # pylint: disable=broad-except - error_handler(exc, traceback.format_exc()) + error_handler(*sys.exc_info(), level=ERROR) @contextmanager @@ -22,7 +27,7 @@ def unrecoverable(error_handler): try: yield except Exception as exc: # pylint: disable=broad-except - error_handler(exc, traceback.format_exc()) + error_handler(*sys.exc_info(), level=ERROR) raise # raise unrecoverableerror from x ? @@ -101,8 +106,10 @@ class LoopingExecutionContext(Wrapper): finally: self._stopped = True - def handle_error(self, exc, trace): - return print_error(exc, trace, context=self.wrapped) + def handle_error(self, exctype, exc, tb): + mondrian.excepthook( + exctype, exc, tb, level=WARNING, context='{} in {}'.format(exctype.__name__, get_name(self)), logger=logger + ) def _get_initial_context(self): if self.parent: diff --git a/bonobo/execution/node.py b/bonobo/execution/node.py index e727531..7781a78 100644 --- a/bonobo/execution/node.py +++ b/bonobo/execution/node.py @@ -3,6 +3,8 @@ from queue import Empty from time import sleep from types import GeneratorType +import sys + from bonobo.constants import NOT_MODIFIED, BEGIN, END from bonobo.errors import InactiveReadableError, UnrecoverableError from bonobo.execution.base import LoopingExecutionContext @@ -101,11 +103,11 @@ class NodeExecutionContext(WithStatistics, LoopingExecutionContext): sleep(self.PERIOD) continue except UnrecoverableError as exc: - self.handle_error(exc, traceback.format_exc()) + self.handle_error(*sys.exc_info()) self.input.shutdown() break except Exception as exc: # pylint: disable=broad-except - self.handle_error(exc, traceback.format_exc()) + self.handle_error(*sys.exc_info()) def step(self): # Pull data from the first available input channel. diff --git a/bonobo/ext/django.py b/bonobo/ext/django.py index d35d131..d9d17f7 100644 --- a/bonobo/ext/django.py +++ b/bonobo/ext/django.py @@ -5,7 +5,6 @@ from django.core.management.base import BaseCommand, OutputWrapper import bonobo import bonobo.util -from bonobo.commands import get_default_services from bonobo.ext.console import ConsoleOutputPlugin from bonobo.util.term import CLEAR_EOL diff --git a/bonobo/settings.py b/bonobo/settings.py index 05d2089..fdc4412 100644 --- a/bonobo/settings.py +++ b/bonobo/settings.py @@ -1,4 +1,5 @@ import logging + import os from bonobo.errors import ValidationError diff --git a/requirements.txt b/requirements.txt index 0b8ada0..35ab601 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ fs==2.0.12 idna==2.6 jinja2==2.9.6 markupsafe==1.0 -mondrian==0.2.0 +mondrian==0.3.0 packaging==16.8 pbr==3.1.1 psutil==5.4.0 diff --git a/setup.py b/setup.py index 2b949c0..9bfecb1 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ setup( packages=find_packages(exclude=['ez_setup', 'example', 'test']), include_package_data=True, install_requires=[ - 'colorama (>= 0.3)', 'fs (>= 2.0, < 2.1)', 'jinja2 (>= 2.9, < 2.10)', 'mondrian (>= 0.2, < 0.3)', + 'colorama (>= 0.3)', 'fs (>= 2.0, < 2.1)', 'jinja2 (>= 2.9, < 2.10)', 'mondrian (>= 0.3, < 0.4)', 'packaging (>= 16, < 17)', 'psutil (>= 5.4, < 6.0)', 'requests (>= 2.0, < 3.0)', 'stevedore (>= 1.27, < 1.28)' ], extras_require={ diff --git a/tests/test_commands.py b/tests/test_commands.py index 8a2c9b8..e7e3523 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -164,7 +164,7 @@ def test_download_works_for_examples(runner): @all_runners def test_download_fails_non_example(runner): with pytest.raises(ValueError): - runner('download', '/something/entirely/different.txt') + runner('download', 'something/entirely/different.txt') @pytest.fixture