Example #1
0
def info(package: str,
         plugin: str,
         func: Optional[str] = None,
         label: Optional[str] = None) -> PluginInfo:
    """Get information about a plug-in"""
    _import(package, plugin)

    try:
        plugin_info = _PLUGINS[package][plugin]
    except KeyError:
        raise _exceptions.UnknownPluginError(
            f"Could not find any plug-in named {plugin!r} inside {package!r}. "
            "Use @pyplugs.register to register functions as plug-ins")

    if func is None:
        func = next(iter(funcs(package, plugin, label=label) + [""]))

    try:
        func_info = plugin_info[func]
    except KeyError:
        raise _exceptions.UnknownPluginFunctionError(
            f"Could not find any function named {func!r} inside '{package}.{plugin}'. "
            "Use @pyplugs.register to register plug-in functions")

    if func_info.label != label:
        raise _exceptions.UnknownPluginFunctionError(
            f"Could not find '{package}.{plugin}.{func}' with label '{label}'. "
            "Use @pyplugs.register to register plug-in functions")

    return func_info
Example #2
0
def info(package: str, plugin: str, func: Optional[str] = None) -> PluginInfo:
    """Get information about a plug-in"""
    _import(package, plugin)

    try:
#        print(f'***************  {package}  {plugin}')
        pack, _ ,plugin = plugin.rpartition('.')
        if pack != '': package += '.' + pack
#        print(f'******  {package}  {plugin}')
       plugin_info = _PLUGINS[package][plugin]
    except KeyError:
        raise _exceptions.UnknownPluginError(
            f"Could not find any plug-in named {plugin!r} inside {package!r}. "
            "Use pyplugs.register to register functions as plug-ins"
        )
Example #3
0
def _import(package: str, plugin: str) -> None:
    """Import the given plugin file from a package"""
    if package in _PLUGINS and plugin in _PLUGINS[package]:
        return

    plugin_module = f"{package}.{plugin}"
    try:
        importlib.import_module(plugin_module)
    except ImportError as err:
        if repr(plugin_module) in err.msg:  # type: ignore
            raise _exceptions.UnknownPluginError(
                f"Plugin {plugin!r} not found in {package!r}") from None
        elif repr(package) in err.msg:  # type: ignore
            raise _exceptions.UnknownPackageError(
                f"Package {package!r} does not exist") from None
        raise
Example #4
0
def info(package: str, plugin: str, func: Optional[str] = None) -> PluginInfo:
    """Get information about a plug-in"""
    _import(package, plugin)

    try:
        plugin_info = _PLUGINS[package][plugin]
    except KeyError:
        raise _exceptions.UnknownPluginError(
            f"Could not find any plug-in named {plugin!r} inside {package!r}. "
            "Use pyplugs.register to register functions as plug-ins")

    func = next(iter(plugin_info.keys())) if func is None else func
    try:
        return plugin_info[func]
    except KeyError:
        raise _exceptions.UnknownPluginFunctionError(
            f"Could not find any function named {func!r} inside '{package}.{plugin}'. "
            "Use pyplugs.register to register plug-in functions")