コード例 #1
0
def import_bus_module(bus_module_name: str = None):
    bus_module_name = bus_module_name or os.environ.get(
        "LIGHTBUS_MODULE", "bus")
    logger.info(f"Importing bus.py from {Bold(bus_module_name)}")
    try:
        bus_module = import_module_from_string(bus_module_name)
    except ImportError as e:
        raise FailedToImportBusModule(
            f"Failed to import bus module at '{bus_module_name}'. Perhaps you "
            f"need to set the LIGHTBUS_MODULE environment variable? Alternatively "
            f"you may need to configure your PYTHONPATH. Error was: {e}")

    if not hasattr(bus_module, "bus"):
        raise FailedToImportBusModule(
            f"Bus module at '{bus_module_name}' contains no attribute named 'bus'.\n"
            f"Your bus module must set a variable named bus using:\n"
            f"     bus = lightbus.create()")

    if not isinstance(bus_module.bus, BusPath):
        raise FailedToImportBusModule(
            f"Bus module at '{bus_module_name}' contains an invalid value for the 'bus' attribute.\n"
            f"We expected a BusPath instance, but found '{type(bus_module.bus).__name__}'.\n"
            f"Your bus module must set a variable named bus using:\n"
            f"     bus = lightbus.create()")

    return bus_module
コード例 #2
0
ファイル: creation.py プロジェクト: rizplate/lightbus
def import_bus_py(bus_module_name: str = None):
    bus_module_name = bus_module_name or os.environ.get(
        "LIGHTBUS_MODULE", "bus")
    logger.info(f"Importing bus.py from {Bold(bus_module_name)}")
    try:
        return import_module_from_string(bus_module_name)
    except ImportError as e:
        raise FailedToImportBusModule(
            f"Failed to import bus module at '{bus_module_name}'. Perhaps you "
            f"need to set the LIGHTBUS_MODULE environment variable? Alternatively "
            f"you may need to configure your PYTHONPATH. Error was: {e}")
コード例 #3
0
ファイル: creation.py プロジェクト: rizplate/lightbus
def load_config(from_file: str = None,
                service_name: str = None,
                process_name: str = None) -> Config:
    from_file = from_file or os.environ.get("LIGHTBUS_CONFIG")

    if from_file:
        logger.info(f"Loading config from {from_file}")
        config = Config.load_file(file_path=from_file)
    else:
        logger.info(f"No config file specified, will use default config")
        config = Config.load_dict({})

    if service_name:
        config._config.set_service_name(service_name)

    if process_name:
        config._config.set_process_name(process_name)

    return config