Skip to content

medcat.plugins.registry

Classes:

Functions:

Attributes:

logger module-attribute

logger = getLogger(__name__)

plugin_registry module-attribute

plugin_registry = PluginRegistry()

PluginInfo dataclass

PluginInfo(name: str, version: str | None = None, author: str | None = None, url: str | None = None, module_paths: list[str] = list(), registered_components: RegisteredComponents = create_empty_reg_comps(), metadata: dict[str, Any] = dict())

Attributes:

author class-attribute instance-attribute

author: str | None = None

metadata class-attribute instance-attribute

metadata: dict[str, Any] = field(default_factory=dict)

module_paths class-attribute instance-attribute

module_paths: list[str] = field(default_factory=list)

name instance-attribute

name: str

registered_components class-attribute instance-attribute

registered_components: RegisteredComponents = field(default_factory=create_empty_reg_comps)

url class-attribute instance-attribute

url: str | None = None

version class-attribute instance-attribute

version: str | None = None

PluginRegistry

PluginRegistry()

Methods:

Source code in medcat-v2/medcat/plugins/registry.py
32
33
def __init__(self):
    self._plugins: dict[str, PluginInfo] = {}

get_all_plugins

get_all_plugins() -> dict[str, PluginInfo]
Source code in medcat-v2/medcat/plugins/registry.py
41
42
def get_all_plugins(self) -> dict[str, PluginInfo]:
    return self._plugins.copy()

get_plugin_info

get_plugin_info(name: str) -> PluginInfo | None
Source code in medcat-v2/medcat/plugins/registry.py
38
39
def get_plugin_info(self, name: str) -> PluginInfo | None:
    return self._plugins.get(name)

register_plugin

register_plugin(plugin_info: PluginInfo)
Source code in medcat-v2/medcat/plugins/registry.py
35
36
def register_plugin(self, plugin_info: PluginInfo):
    self._plugins[plugin_info.name] = plugin_info

RegisteredComponents

Bases: TypedDict

Attributes:

addons instance-attribute

addons: list[tuple[str, str]]

core instance-attribute

core: dict[str, list[tuple[str, str]]]

create_empty_reg_comps

create_empty_reg_comps() -> RegisteredComponents
Source code in medcat-v2/medcat/plugins/registry.py
15
16
def create_empty_reg_comps() -> RegisteredComponents:
    return {"core": {}, "addons": []}

find_provider

find_provider(component: BaseComponent) -> str
Source code in medcat-v2/medcat/plugins/registry.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def find_provider(component: BaseComponent) -> str:
    all_plugins = plugin_registry.get_all_plugins()
    provider = "medcat"  # Default provider
    component_identifier = ""
    if component.is_core():
        core_comp = cast(CoreComponent, component)
        component_type = core_comp.get_type().name
        component_name = component.name
        component_identifier = f"core:{component_type}:{component_name}"
    else:
        component_name = component.name
        component_identifier = f"addon:{component_name}"

    # Check if this component is provided by a plugin via direct registration
    for plugin_info in all_plugins.values():
        found = False
        # Check core components registered by the plugin
        core_comps = plugin_info.registered_components["core"].items()
        for c_type, registered_comps in core_comps:
            for reg_comp_name, _ in registered_comps:
                if component_identifier == f"core:{c_type}:{reg_comp_name}":
                    provider = plugin_info.name
                    found = True
                    break
            if found:
                break
        if found:
            break

        # If not found in core, check addon components registered by the plugin
        if not found:
            for reg_comp_name, _ in plugin_info.registered_components["addons"]:
                if component_identifier == f"addon:{reg_comp_name}":
                    provider = plugin_info.name
                    found = True
                    break
        if found:
            break

    # Fallback: If not found by explicit registration, check module paths
    if provider == "medcat":
        component_module = component.__class__.__module__
        for plugin_info in all_plugins.values():
            for module_path in plugin_info.module_paths:
                if component_module.startswith(module_path):
                    provider = plugin_info.name
                    # register component with plugin
                    _late_register(component, plugin_info)
                    break
            if provider != "medcat":  # If a provider was found, break outer loop
                break
    return provider