(bus_module_name: str = None)
return bus_module
Get the bus module, importing if necessary

    The bus module is determined as follows:

      1. The bus_module_name, if present
      2. The `LIGHTBUS_MODULE` environment variable, if present
      3. Otherwise, the default of `bus` will be used
Get the bus module, importing if necessary
Get the bus module importing if necessary
def import_bus_module(bus_module_name: str = None):
    """Get the bus module, importing if necessary

    The bus module is determined as follows:

      1. The bus_module_name, if present
      2. The `LIGHTBUS_MODULE` environment variable, if present
      3. Otherwise, the default of `bus` will be used
    """
    bus_module_name = bus_module_name or os.environ.get("LIGHTBUS_MODULE", "") or "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 '{bus_module_name}'.\n\n"
            "    Perhaps you need to set the LIGHTBUS_MODULE environment variable? Alternatively "
            "you may need to configure your PYTHONPATH.\n\n"
            f"    Error was: {e}"
        )

    if not hasattr(bus_module, "bus"):
        raise FailedToImportBusModule(
            f"Bus module at '{bus_module_name}' contains no attribute named 'bus'.\n\n"
            "    Your bus module must set a variable named bus using:\n"
            "        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\n    We expected a BusPath instance, but found"
            f" '{type(bus_module.bus).__name__}'.\n    Your bus module must contain a variable"
            " named 'bus' using:\n        bus = lightbus.create()"
        )

    return bus_module
def import_bus_module ( bus_module_name : str = None ) : bus_module_name = bus_module_name or os . environ . get ( "LIGHTBUS_MODULE" , "" ) or "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 '{bus_module_name}'.\n\n" "    Perhaps you need to set the LIGHTBUS_MODULE environment variable? Alternatively " "you may need to configure your PYTHONPATH.\n\n" f"    Error was: {e}" ) if not hasattr ( bus_module , "bus" ) : raise FailedToImportBusModule ( f"Bus module at '{bus_module_name}' contains no attribute named 'bus'.\n\n" "    Your bus module must set a variable named bus using:\n" "        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\n    We expected a BusPath instance, but found" f" '{type(bus_module.bus).__name__}'.\n    Your bus module must contain a variable" " named 'bus' using:\n        bus = lightbus.create()" ) return bus_module