def main(args): if '.' not in sys.path: sys.path.insert(0, '.') if args.config: with open(args.config) as fle: config = yaml.safe_load(fle) else: config = {AMQP_URI_CONFIG_KEY: args.broker} if args.logging_config_file: logging.config.fileConfig(args.logging_config_file, disable_existing_loggers=False) elif 'LOGGING' in config: logging.config.dictConfig(config['LOGGING']) else: logging.basicConfig(level=logging.INFO, format='%(message)s') services = [] for path in args.services: services.extend(import_service(path)) kwargs = {'backdoor_port': args.backdoor_port} if config.get(AUTORELOAD_CONFIG_KEY): logger.info('autoreload enabled') autoreload.make_autoreload(run, args=(services, config), kwargs=kwargs) else: run(services, config, **kwargs)
def run(services=None, name=None, backdoor_port=None): from nameko.cli.run import import_service, run as nameko_run if services is None: services = [EventSender] for module_name in settings.SERVICE_MODULES: services.extend(import_service(module_name)) if services: config = get_config(settings.NAMEKO_CONFIG, name=name) nameko_run(services, config, backdoor_port=backdoor_port)
def main(args): if '.' not in sys.path: sys.path.insert(0, '.') if args.config: with open(args.config) as fle: config = yaml.load(fle) else: config = {AMQP_URI_CONFIG_KEY: args.broker} if args.listen: config[WEB_SERVER_CONFIG_KEY] = args.listen if "LOGGING" in config: logging.config.dictConfig(config['LOGGING']) else: logging.basicConfig(level=logging.INFO, format='%(message)s') services = [] for path in args.services: services.extend(import_service(path)) run(services, config, backdoor_port=args.backdoor_port)
def test_import_not_a_class(): with pytest.raises(CommandError) as exc: import_service('test.sample:rpc') assert "Service must be a class" in str(exc)
def test_import_no_service_classes(): with pytest.raises(CommandError): import_service('test')
def test_import_broken(): with pytest.raises(ImportError): import_service('test.broken_sample')
def test_import_missing_class(): with pytest.raises(CommandError) as exc: import_service('test.sample:NonExistent') assert "Failed to find service class" in str(exc)
def test_import_missing(): with pytest.raises(CommandError) as exc: import_service('non_existent') assert "No module named" in str(exc.value) assert "non_existent" in str(exc.value)
def test_import_filename(): with pytest.raises(CommandError) as exc: import_service('test/sample.py') assert "did you mean 'test.sample'?" in str(exc)
def test_import_ok(): assert import_service('test.sample') == [Service] assert import_service('test.sample:Service') == [Service]