示例#1
0
def test_methods_differ_from_baseclass_table_plugin_names():
    """Show plugin name"""
    def get_plugin_function(plugin_registry_key: str):
        if plugin_registry_key == "base":
            return MockPlugin
        elif plugin_registry_key == "sub_class":
            return MockPluginSubclass

    result = methods_differ_from_baseclass_table("some_method",
                                                 "base",
                                                 get_plugin_function,
                                                 MockPlugin,
                                                 plugin_names=True)

    assert result == [["`base`", False, "`test_base_registry.MockPlugin`"]]
def data_io_plugin_table() -> str:
    """Return registered data io plugins and which functions they support as markdown table.

    This is especially useful when you work with new plugins.

    Returns
    -------
    str
        Markdown table of data io plugins.
    """
    table_data = methods_differ_from_baseclass_table(
        DATA_IO_METHODS, known_data_formats(), get_data_io, DataIoInterface
    )
    headers = tuple(map(lambda x: f"__{x}__", ["Plugin", *DATA_IO_METHODS]))
    return tabulate(
        bool_table_repr(table_data), tablefmt="github", headers=headers, stralign="center"
    )
示例#3
0
def test_methods_differ_from_baseclass_table(
    method_names: str | list[str],
    plugin_registry_keys: str | list[str],
    expected: list[list[str | bool]],
):
    """Inherited methods are the same as base class and overwritten ones differ"""
    def get_plugin_function(plugin_registry_key: str):
        if plugin_registry_key == "base":
            return MockPlugin
        elif plugin_registry_key in {"sub_class", "sub_class_inst"}:
            return MockPluginSubclass

    result = methods_differ_from_baseclass_table(method_names,
                                                 plugin_registry_keys,
                                                 get_plugin_function,
                                                 MockPlugin)

    assert result == expected
示例#4
0
def project_io_plugin_table(
    *, plugin_names: bool = False, full_names: bool = False
) -> MarkdownStr:
    """Return registered project io plugins and which functions they support as markdown table.

    This is especially useful when you work with new plugins.

    Parameters
    ----------
    plugin_names : bool
        Whether or not to add the names of the plugins to the table.
    full_names : bool
        Whether to display the full names the plugins are
        registered under as well.

    Returns
    -------
    MarkdownStr
        Markdown table of project io plugins.
    """
    table_data = methods_differ_from_baseclass_table(
        PROJECT_IO_METHODS,
        known_project_formats(full_names=full_names),
        get_project_io,
        ProjectIoInterface,
        plugin_names=plugin_names,
    )
    header_values = ["Format name", *PROJECT_IO_METHODS]
    if plugin_names:
        header_values.append("Plugin name")
    headers = tuple(map(lambda x: f"__{x}__", header_values))
    return MarkdownStr(
        tabulate(
            bool_table_repr(table_data), tablefmt="github", headers=headers, stralign="center"
        )
    )
示例#5
0
def project_io_list_supporting_plugins(
        method_name: str,
        block_list: Iterable[str] | None = None) -> Iterable[str]:
    """List all project-io plugin that implement ``method_name``.

    Parameters
    ----------
    method_name: str
        Name of the method which should be supported.
    block_list: Iterable[str]
        Iterable of plugin names which should be omitted.
    """
    if block_list is None:
        block_list = []
    support_table = methods_differ_from_baseclass_table(
        method_names=method_name,
        plugin_registry_keys=known_project_formats(full_names=False),
        get_plugin_function=get_project_io,
        base_class=ProjectIoInterface,
    )
    support_table = filter(lambda entry: entry[1], support_table)
    supporting_list: Iterable[str] = (entry[0].replace("`", "")
                                      for entry in support_table)
    return list(filter(lambda entry: entry not in block_list, supporting_list))