[errors] Move error handling in transformations to use mondrian.

This commit is contained in:
Romain Dorgueil
2017-11-02 00:08:09 +01:00
parent 58923f4a84
commit fb86bc9507
15 changed files with 45 additions and 31 deletions

View File

@ -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

View File

@ -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)

View File

@ -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'))