def handle(cls, config_filename, *, pipeline, action, force=False, verbose=False): dispatcher = LoggingDispatcher() variables, features, files, config = _read_configuration( dispatcher, config_filename) if not pipeline: raise ValueError( "You must choose a pipeline to run. Available choices: {}.". format(", ".join(sorted(config.pipelines.keys())))) if not pipeline in config.pipelines: raise ValueError( "Undefined pipeline {!r}. Valid choices are: {}.".format( pipeline, ", ".join(sorted(config.pipelines.keys())))) pipeline = ConfiguredPipeline(pipeline, config.pipelines[pipeline], config) path = os.path.dirname(config_filename) pipeline_file = os.path.join(path, ".medikit/pipelines", pipeline.name + ".json") pipeline_dirname = os.path.dirname(pipeline_file) if not os.path.exists(pipeline_dirname): os.makedirs(pipeline_dirname) elif not os.path.isdir(pipeline_dirname): raise NotADirectoryError( 'The pipeline state path "{}" was found but is not a directory...' .format(pipeline_dirname)) if not action: raise RuntimeError( "Choose a pipeline action: start, continue, abort.") while action: if action == START: action = cls._handle_start(pipeline, filename=pipeline_file, force=force) elif action == CONTINUE: action = cls._handle_continue(pipeline, filename=pipeline_file) elif action == ABORT: action = cls._handle_abort(pipeline, filename=pipeline_file) elif action == COMPLETE: target = os.path.join( ".medikit/pipelines", pipeline.name + "." + str(datetime.datetime.now()).replace( ":", ".").replace(" ", ".") + ".json", ) os.rename(pipeline_file, os.path.join(path, target)) logger.info( "Pipeline complete. State saved as “{}”.".format(target)) break else: raise ValueError("Invalid action “{}”.".format(action)) force = False
def handle(config_filename, **kwargs): import logging logger = logging.getLogger() dispatcher = LoggingDispatcher() variables, features, files, config = _read_configuration( dispatcher, config_filename) feature_instances = {} logger.info('Updating {} with {} features'.format( term.bold(config['python'].get('name')), ', '.join( term.bold(term.green(feature_name)) for feature_name in sorted(features)))) all_features = load_feature_extensions() sorted_features = sorted( features) # sort to have a predictable display order for feature_name in sorted_features: logger.debug('Initializing feature {}...'.format( term.bold(term.green(feature_name)))) try: feature = all_features[feature_name] except KeyError as exc: logger.exception( 'Feature "{}" not found.'.format(feature_name)) if feature: feature_instances[feature_name] = feature(dispatcher) for req in feature_instances[feature_name].requires: if not req in sorted_features: raise RuntimeError( 'Unmet dependency: {} requires {}.'.format( feature_name, req)) for con in feature_instances[feature_name].conflicts: if con in sorted_features: raise RuntimeError( 'Conflicting dependency: {} conflicts with {}.'. format(con, feature_name)) else: raise RuntimeError( 'Required feature {} not found.'.format(feature_name)) event = ProjectEvent(config=config) event.variables, event.files = variables, files # todo: add listener dump list in debug/verbose mode ? event = dispatcher.dispatch('medikit.on_start', event) dispatcher.dispatch('medikit.on_end', event) logger.info('Done.')
def handle(config_filename, **kwargs): import logging logger = logging.getLogger() dispatcher = LoggingDispatcher() variables, features, files, config = _read_configuration(dispatcher, config_filename) # This is a hack, but we'd need a flexible option parser which requires too much work as of today. if kwargs.pop("override_requirements", False): if "python" in config: config["python"].override_requirements = True feature_instances = {} logger.info( "Updating {} with {} features".format( term.bold(config.package_name), ", ".join(term.bold(term.green(feature_name)) for feature_name in sorted(features)), ) ) all_features = load_feature_extensions() sorted_features = sorted(features) # sort to have a predictable display order for feature_name in sorted_features: logger.debug("Initializing feature {}...".format(term.bold(term.green(feature_name)))) try: feature = all_features[feature_name] except KeyError as exc: logger.exception('Feature "{}" not found.'.format(feature_name)) if feature: feature_instances[feature_name] = feature(dispatcher) for req in feature_instances[feature_name].requires: if not req in sorted_features: raise RuntimeError("Unmet dependency: {} requires {}.".format(feature_name, req)) for con in feature_instances[feature_name].conflicts: if con in sorted_features: raise RuntimeError("Conflicting dependency: {} conflicts with {}.".format(con, feature_name)) else: raise RuntimeError("Required feature {} not found.".format(feature_name)) event = ProjectEvent(config=config) event.variables, event.files = variables, files # todo: add listener dump list in debug/verbose mode ? event = dispatcher.dispatch("medikit.on_start", event) dispatcher.dispatch("medikit.on_end", event) logger.info("Done.")
def handle(cls, config_filename, *, pipeline, action, force=False, verbose=False): dispatcher = LoggingDispatcher() variables, features, files, config = _read_configuration(dispatcher, config_filename) if not pipeline: raise ValueError( "You must choose a pipeline to run. Available choices: {}.".format( ", ".join(sorted(config.pipelines.keys())) ) ) if not pipeline in config.pipelines: raise ValueError( "Undefined pipeline {!r}. Valid choices are: {}.".format( pipeline, ", ".join(sorted(config.pipelines.keys())) ) ) pipeline = ConfiguredPipeline(pipeline, config.pipelines[pipeline], config) path = os.path.dirname(config_filename) pipeline_file = os.path.join(path, ".medikit/pipelines", pipeline.name + ".json") pipeline_dirname = os.path.dirname(pipeline_file) if not os.path.exists(pipeline_dirname): os.makedirs(pipeline_dirname) elif not os.path.isdir(pipeline_dirname): raise NotADirectoryError( 'The pipeline state path "{}" was found but is not a directory...'.format(pipeline_dirname) ) if not action: raise RuntimeError("Choose a pipeline action: start, continue, abort.") while action: if action == START: action = cls._handle_start(pipeline, filename=pipeline_file, force=force) elif action == CONTINUE: action = cls._handle_continue(pipeline, filename=pipeline_file) elif action == ABORT: action = cls._handle_abort(pipeline, filename=pipeline_file) elif action == COMPLETE: target = os.path.join( ".medikit/pipelines", pipeline.name + "." + str(datetime.datetime.now()).replace(":", ".").replace(" ", ".") + ".json", ) os.rename(pipeline_file, os.path.join(path, target)) logger.info("Pipeline complete. State saved as “{}”.".format(target)) break else: raise ValueError("Invalid action “{}”.".format(action)) force = False
def handle(config_filename, **kwargs): import logging logger = logging.getLogger() dispatcher = LoggingDispatcher() variables, features, files, config = _read_configuration( dispatcher, config_filename) # This is a hack, but we'd need a flexible option parser which requires too much work as of today. if kwargs.pop("override_requirements", False): if "python" in config: config["python"].override_requirements = True feature_instances = {} logger.info("Updating {} with {} features".format( term.bold(config.package_name), ", ".join( term.bold(term.green(feature_name)) for feature_name in sorted(features)), )) all_features = load_feature_extensions() sorted_features = sorted( features) # sort to have a predictable display order for feature_name in sorted_features: logger.debug('Initializing feature "{}"...'.format( term.bold(term.green(feature_name)))) try: feature = all_features[feature_name] except KeyError as exc: logger.exception( 'Feature "{}" not found.'.format(feature_name)) if feature: feature_instances[feature_name] = feature(dispatcher) for req in feature_instances[feature_name].requires: if not req in sorted_features: raise RuntimeError( 'Unmet dependency: "{}" requires "{}".'.format( feature_name, req)) for con in feature_instances[feature_name].conflicts: if con in sorted_features: raise RuntimeError( 'Conflicting dependency: "{}" conflicts with "{}".' .format(con, feature_name)) else: raise RuntimeError( "Required feature {} not found.".format(feature_name)) event = ProjectEvent(config=config) event.variables, event.files = variables, files # todo: add listener dump list in debug/verbose mode ? event = dispatcher.dispatch(medikit.on_start, event) dispatcher.dispatch(medikit.on_end, event) logger.info("Done.")