Exemple #1
0
def get_transport_name(cls: Type["Transport"]):
    for type_ in ("rpc", "result", "event"):
        for *_, name, class_ in load_entrypoint_classes(f"lightbus_{type_}_transports"):
            if cls == class_:
                return name

    raise TransportNotFound(
        f"Transport class {cls.__module__}.{cls.__name__} is not specified in any entrypoint."
    )
Exemple #2
0
def get_available_transports(type_):
    loaded = load_entrypoint_classes(f"lightbus_{type_}_transports")

    if not loaded:
        raise TransportsNotInstalled(
            f"No {type_} transports are available, which means lightbus has not been "
            f"installed correctly. This is likely because you are working on Lightbus itself. "
            f"In which case, within your local lightbus repo you should run "
            f"something like 'pip install .' or 'python setup.py develop'.\n\n"
            f"This will install the entrypoints (defined in setup.py) which point Lightbus "
            f"to it's bundled transports.")
    return {name: class_ for module_name, name, class_ in loaded}
Exemple #3
0
def find_plugins() -> Dict[str, Type[LightbusPlugin]]:
    """Discover available plugin classes using the 'lightbus_plugins' entrypoint
    """
    available_plugin_classes = load_entrypoint_classes(ENTRYPOINT_NAME)
    available_plugin_classes = sorted(available_plugin_classes, key=lambda v: v[-1].priority)

    plugins = OrderedDict()
    for module_name, name, plugin in available_plugin_classes:
        if name in plugins:
            pass
        plugins[name] = plugin

    return plugins
Exemple #4
0
def get_available_transports(type_):
    loaded = load_entrypoint_classes(f"lightbus_{type_}_transports")

    return {name: class_ for module_name, name, class_ in loaded}