@ -1,12 +1,13 @@
|
||||
import argparse
|
||||
|
||||
import logging
|
||||
from stevedore import ExtensionManager
|
||||
from bonobo import logging, settings
|
||||
|
||||
logger = logging.get_logger()
|
||||
|
||||
|
||||
def entrypoint(args=None):
|
||||
logging.basicConfig()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--debug', '-D', action='store_true')
|
||||
|
||||
subparsers = parser.add_subparsers(dest='command')
|
||||
subparsers.required = True
|
||||
@ -18,10 +19,17 @@ def entrypoint(args=None):
|
||||
parser = subparsers.add_parser(ext.name)
|
||||
commands[ext.name] = ext.plugin(parser)
|
||||
except Exception:
|
||||
logging.exception('Error while loading command {}.'.format(ext.name))
|
||||
logger.exception('Error while loading command {}.'.format(ext.name))
|
||||
|
||||
from stevedore import ExtensionManager
|
||||
mgr = ExtensionManager(namespace='bonobo.commands')
|
||||
mgr.map(register_extension)
|
||||
|
||||
args = parser.parse_args(args).__dict__
|
||||
if args.pop('debug', False):
|
||||
settings.DEBUG = True
|
||||
settings.LOGGING_LEVEL = logging.DEBUG
|
||||
logging.set_level(settings.LOGGING_LEVEL)
|
||||
|
||||
logger.debug('Command: ' + args['command'] + ' Arguments: ' + repr(args))
|
||||
commands[args.pop('command')](**args)
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
import os
|
||||
|
||||
|
||||
def execute(name):
|
||||
try:
|
||||
from cookiecutter.main import cookiecutter
|
||||
|
||||
@ -1,10 +1,4 @@
|
||||
import importlib
|
||||
import os
|
||||
import runpy
|
||||
|
||||
import pip
|
||||
|
||||
import bonobo
|
||||
|
||||
DEFAULT_SERVICES_FILENAME = '_services.py'
|
||||
DEFAULT_SERVICES_ATTR = 'get_services'
|
||||
@ -12,7 +6,6 @@ DEFAULT_SERVICES_ATTR = 'get_services'
|
||||
DEFAULT_GRAPH_FILENAME = '__main__.py'
|
||||
DEFAULT_GRAPH_ATTR = 'get_graph'
|
||||
|
||||
|
||||
def get_default_services(filename, services=None):
|
||||
dirname = os.path.dirname(filename)
|
||||
services_filename = os.path.join(dirname, DEFAULT_SERVICES_FILENAME)
|
||||
@ -33,7 +26,8 @@ def get_default_services(filename, services=None):
|
||||
|
||||
|
||||
def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
from bonobo import settings
|
||||
import runpy
|
||||
from bonobo import Graph, run, settings
|
||||
|
||||
if quiet:
|
||||
settings.QUIET = True
|
||||
@ -44,6 +38,8 @@ def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
if filename:
|
||||
if os.path.isdir(filename):
|
||||
if install:
|
||||
import importlib
|
||||
import pip
|
||||
requirements = os.path.join(filename, 'requirements.txt')
|
||||
pip.main(['install', '-r', requirements])
|
||||
# Some shenanigans to be sure everything is importable after this, especially .egg-link files which
|
||||
@ -62,7 +58,7 @@ def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
else:
|
||||
raise RuntimeError('UNEXPECTED: argparse should not allow this.')
|
||||
|
||||
graphs = dict((k, v) for k, v in context.items() if isinstance(v, bonobo.Graph))
|
||||
graphs = dict((k, v) for k, v in context.items() if isinstance(v, Graph))
|
||||
|
||||
assert len(graphs) == 1, (
|
||||
'Having zero or more than one graph definition in one file is unsupported for now, '
|
||||
@ -73,7 +69,7 @@ def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
|
||||
# todo if console and not quiet, then add the console plugin
|
||||
# todo when better console plugin, add it if console and just disable display
|
||||
return bonobo.run(
|
||||
return run(
|
||||
graph,
|
||||
plugins=[],
|
||||
services=get_default_services(
|
||||
@ -82,8 +78,8 @@ def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
)
|
||||
|
||||
|
||||
def register_generic_run_arguments(parser):
|
||||
source_group = parser.add_mutually_exclusive_group(required=True)
|
||||
def register_generic_run_arguments(parser, required=True):
|
||||
source_group = parser.add_mutually_exclusive_group(required=required)
|
||||
source_group.add_argument('filename', nargs='?', type=str)
|
||||
source_group.add_argument('--module', '-m', type=str)
|
||||
return parser
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
import bonobo
|
||||
from bonobo.util.pkgs import bonobo_packages
|
||||
|
||||
|
||||
def format_version(mod, *, name=None, quiet=False):
|
||||
from bonobo.util.pkgs import bonobo_packages
|
||||
args = {
|
||||
'name': name or mod.__name__,
|
||||
'version': mod.__version__,
|
||||
@ -20,6 +17,9 @@ def format_version(mod, *, name=None, quiet=False):
|
||||
|
||||
|
||||
def execute(all=False, quiet=False):
|
||||
import bonobo
|
||||
from bonobo.util.pkgs import bonobo_packages
|
||||
|
||||
print(format_version(bonobo, quiet=quiet))
|
||||
if all:
|
||||
for name in sorted(bonobo_packages):
|
||||
|
||||
Reference in New Issue
Block a user