def entrypoint(args=None): """ Main callable for "bonobo" entrypoint. Will load commands from "bonobo.commands" entrypoints, using stevedore. """ mondrian.setup(excepthook=True) logger = logging.getLogger() logger.setLevel(settings.LOGGING_LEVEL.get()) parser = argparse.ArgumentParser() parser.add_argument("--debug", "-D", action="store_true") subparsers = parser.add_subparsers(dest="command") subparsers.required = True commands = {} def register_extension(ext): nonlocal commands try: parser = subparsers.add_parser(ext.name) if isinstance(ext.plugin, type) and issubclass( ext.plugin, BaseCommand): # current way, class based. cmd = ext.plugin() cmd.add_arguments(parser) cmd.__name__ = ext.name commands[ext.name] = cmd.handle else: # old school, function based. commands[ext.name] = ext.plugin(parser) except Exception: logger.exception("Error while loading command {}.".format( ext.name)) from stevedore import ExtensionManager mgr = ExtensionManager(namespace="bonobo.commands") mgr.map(register_extension) parsed_args = parser.parse_args(args).__dict__ if parsed_args.pop("debug", False): settings.DEBUG.set(True) settings.LOGGING_LEVEL.set(logging.DEBUG) logger.setLevel(settings.LOGGING_LEVEL.get()) logger.debug("Command: " + parsed_args["command"] + " Arguments: " + repr(parsed_args)) # Get command handler, execute, rince. command = commands[parsed_args.pop("command")] command(**parsed_args) return 0
def cli(): """ This script lets you control various aspects of Mereswine from the command line. """ logger = logging.getLogger() mondrian.setup(excepthook=True) logger.setLevel(logging.DEBUG if current_app.debug else logging.INFO)
def run(graph, *, plugins=None, services=None, strategy=None): """ Main entry point of bonobo. It takes a graph and creates all the necessary plumbing 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.execution.strategies.base.Strategy` to use. :param list plugins: The list of plugins to enhance execution. :param dict services: The implementations of services this graph will use. :return bonobo.execution.graph.GraphExecutionContext: """ plugins = plugins or [] from bonobo import settings settings.check() if not settings.QUIET.get(): # pragma: no cover if _is_interactive_console(): import mondrian mondrian.setup(excepthook=True) from bonobo.plugins.console import ConsoleOutputPlugin if ConsoleOutputPlugin not in plugins: plugins.append(ConsoleOutputPlugin) if _is_jupyter_notebook(): try: from bonobo.contrib.jupyter import JupyterOutputPlugin except ImportError: import logging logging.warning( 'Failed to load jupyter widget. Easiest way is to install the optional "jupyter" ' 'dependencies with «pip install bonobo[jupyter]», but you can also install a specific ' 'version by yourself.') else: if JupyterOutputPlugin not in plugins: plugins.append(JupyterOutputPlugin) import logging logging.getLogger().setLevel(settings.LOGGING_LEVEL.get()) strategy = create_strategy(strategy) return strategy.execute(graph, plugins=plugins, services=services)
def run(graph, *, plugins=None, services=None, strategy=None): """ Main entry point of bonobo. It takes a graph and creates all the necessary plumbing 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.execution.strategies.base.Strategy` to use. :param list plugins: The list of plugins to enhance execution. :param dict services: The implementations of services this graph will use. :return bonobo.execution.graph.GraphExecutionContext: """ plugins = plugins or [] from bonobo import settings settings.check() if not settings.QUIET.get(): # pragma: no cover if _is_interactive_console(): import mondrian mondrian.setup(excepthook=True) from bonobo.plugins.console import ConsoleOutputPlugin if ConsoleOutputPlugin not in plugins: plugins.append(ConsoleOutputPlugin) if _is_jupyter_notebook(): try: from bonobo.contrib.jupyter import JupyterOutputPlugin except ImportError: import logging logging.warning( 'Failed to load jupyter widget. Easiest way is to install the optional "jupyter" ' 'dependencies with «pip install bonobo[jupyter]», but you can also install a specific ' 'version by yourself.' ) else: if JupyterOutputPlugin not in plugins: plugins.append(JupyterOutputPlugin) import logging logging.getLogger().setLevel(settings.LOGGING_LEVEL.get()) strategy = create_strategy(strategy) return strategy.execute(graph, plugins=plugins, services=services)
def main(args=None): if not sys.warnoptions: logging.captureWarnings(True) warnings.simplefilter("default", DeprecationWarning) mondrian.setup(excepthook=True) logger = logging.getLogger() logger.setLevel(logging.INFO) logging.getLogger("pip._vendor.cachecontrol.controller").setLevel( logging.ERROR) cli = MedikitCommand() options, more_args = cli.parser.parse_known_args( args if args is not None else sys.argv[1:]) if options.verbose: logger.setLevel(logging.DEBUG) options = vars(options) command, handler = options.pop("command"), options.pop("_handler") config_filename = os.path.join(os.getcwd(), options.pop("target", "."), options.pop("config")) version = medikit.__version__ try: if os.path.exists( os.path.join( os.path.dirname(os.path.dirname(medikit.__file__)), ".git")): try: version = (check_output( ["git", "describe"], cwd=os.path.dirname(os.path.dirname( medikit.__file__))).decode("utf-8").strip() + " (git)") except: version = (check_output( ["git", "rev-parse", "HEAD"], cwd=os.path.dirname(os.path.dirname( medikit.__file__))).decode("utf-8").strip()[0:7] + " (git)") except: warnings.warn( "Git repository found, but could not find version number from the repository." ) print( mondrian.term.lightwhite_bg( mondrian.term.red(" ✚ Medikit v." + version + " ✚ "))) if len(more_args): return handler(config_filename, more=more_args, **options) else: return handler(config_filename, **options)
def main(args=None): if not sys.warnoptions: logging.captureWarnings(True) warnings.simplefilter("default", DeprecationWarning) mondrian.setup(excepthook=True) logger = logging.getLogger() logger.setLevel(logging.INFO) cli = MedikitCommand() options, more_args = cli.parser.parse_known_args( args if args is not None else sys.argv[1:]) if options.verbose: logger.setLevel(logging.DEBUG) options = vars(options) command, handler = options.pop('command'), options.pop('_handler') config_filename = os.path.join(os.getcwd(), options.pop('target', '.'), options.pop('config')) version = medikit.__version__ try: if os.path.exists( os.path.join( os.path.dirname(os.path.dirname(medikit.__file__)), '.git')): try: version = check_output( ['git', 'describe'], cwd=os.path.dirname(os.path.dirname( medikit.__file__))).decode('utf-8').strip() + ' (git)' except: version = check_output( ['git', 'rev-parse', 'HEAD'], cwd=os.path.dirname(os.path.dirname(medikit.__file__)) ).decode('utf-8').strip()[0:7] + ' (git)' except: warnings.warn( 'Git repository found, but could not find version number from the repository.' ) print( mondrian.term.lightwhite_bg( mondrian.term.red(' ✚ Medikit v.' + version + ' ✚ '))) if len(more_args): return handler(config_filename, more=more_args, **options) else: return handler(config_filename, **options)
def main(args=None): if not sys.warnoptions: logging.captureWarnings(True) warnings.simplefilter("default", DeprecationWarning) mondrian.setup(excepthook=True) logger = logging.getLogger() logger.setLevel(logging.INFO) logging.getLogger("pip._vendor.cachecontrol.controller").setLevel(logging.ERROR) cli = MedikitCommand() options, more_args = cli.parser.parse_known_args(args if args is not None else sys.argv[1:]) if options.verbose: logger.setLevel(logging.DEBUG) options = vars(options) command, handler = options.pop("command"), options.pop("_handler") config_filename = os.path.join(os.getcwd(), options.pop("target", "."), options.pop("config")) version = medikit.__version__ try: if os.path.exists(os.path.join(os.path.dirname(os.path.dirname(medikit.__file__)), ".git")): try: version = ( check_output(["git", "describe"], cwd=os.path.dirname(os.path.dirname(medikit.__file__))) .decode("utf-8") .strip() + " (git)" ) except: version = ( check_output(["git", "rev-parse", "HEAD"], cwd=os.path.dirname(os.path.dirname(medikit.__file__))) .decode("utf-8") .strip()[0:7] + " (git)" ) except: warnings.warn("Git repository found, but could not find version number from the repository.") print(mondrian.term.lightwhite_bg(mondrian.term.red(" ✚ Medikit v." + version + " ✚ "))) if len(more_args): return handler(config_filename, more=more_args, **options) else: return handler(config_filename, **options)
def main(): mondrian.setup(excepthook=True) sys.path = list(dict.fromkeys([os.getcwd(), *sys.path])) try: __import__("config") except ImportError: pass parser = argparse.ArgumentParser() parser.add_argument("--debug", "-D", action="store_true") subparsers = parser.add_subparsers(dest="command") subparsers.required = True for command, CommandType in commands.items(): if CommandType.is_enabled(): subparser = subparsers.add_parser(command) command_instance = CommandType() command_instance.add_arguments(subparser) subparser.set_defaults(handler=command_instance.handle) options, rest = parser.parse_known_args() options = options.__dict__ options.pop("command") debug = options.pop("debug") handler = options.pop("handler") if debug: logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().debug("Logging level set to DEBUG") try: with humanizer.humanize(): return handler(*rest, **options) except Exception: return 70
import os import re import struct from io import BytesIO from pathlib import Path, posixpath import bonobo import mondrian import pydicom from bonobo.config import use from botocore.exceptions import ClientError from warehouse.components import constants, helpers, services # set up logging mondrian.setup(excepthook=True) logger = logging.getLogger() logger.setLevel(logging.INFO) BUCKET_NAME = os.getenv("WAREHOUSE_BUCKET", default=None) DRY_RUN = bool(os.getenv("DRY_RUN", default=False)) if DRY_RUN: logger.info("This is a **dry run** with no file intended to be changed.") KB = 1024 ### # Helpers ### def patient_in_training_set( patient_id, training_percent=constants.TRAINING_PERCENTAGE
def main(args=None): mondrian.setup(excepthook=True) logger = logging.getLogger() logger.setLevel(logging.INFO) parser = argparse.ArgumentParser() parser.add_argument('--config', '-c', default='Projectfile') parser.add_argument('--verbose', '-v', action='store_true', default=False) subparsers = parser.add_subparsers(dest='command') subparsers.required = True # todo aliases for update/init # warning: http://bugs.python.org/issue9234 parser_init = subparsers.add_parser('init', help='Initialize a new project.') parser_init.set_defaults(handler=handle_init) parser_init.add_argument('target') parser_init.add_argument('--name') parser_init.add_argument('--description') parser_init.add_argument('--license') parser_init.add_argument('--feature', '-f', action='append', dest='features') parser_update = subparsers.add_parser('update', help='Update current project.') parser_update.set_defaults(handler=handle_update) parser_pipeline = subparsers.add_parser( 'pipeline', help='Execute multi-steps pipelines (release, etc.).') parser_pipeline.set_defaults(handler=handle_pipeline) parser_pipeline.add_argument('pipeline') parser_pipeline.add_argument('action', choices=( START, CONTINUE, ABORT, )) parser_pipeline.add_argument('--force', '-f', action='store_true') options, more_args = parser.parse_known_args( args if args is not None else sys.argv[1:]) if options.verbose: logger.setLevel(logging.DEBUG) options = vars(options) command, handler = options.pop('command'), options.pop('handler') config_filename = os.path.join(os.getcwd(), options.pop('target', '.'), options.pop('config')) version = medikit.__version__ try: if os.path.exists( os.path.join( os.path.dirname(os.path.dirname(medikit.__file__)), '.git')): try: version = check_output( ['git', 'describe'], cwd=os.path.dirname(os.path.dirname( medikit.__file__))).decode('utf-8').strip() + ' (git)' except: version = check_output( ['git', 'rev-parse', 'HEAD'], cwd=os.path.dirname(os.path.dirname(medikit.__file__)) ).decode('utf-8').strip()[0:7] + ' (git)' except: warnings.warn( 'Git repository found, but could not find version number from the repository.' ) print( mondrian.term.lightwhite_bg( mondrian.term.red(' ✚ Medikit v.' + version + ' ✚ '))) if len(more_args): return handler(config_filename, more=more_args, **options) else: return handler(config_filename, **options)