Skip to content

Commit f9e6f41

Browse files
committed
Extract processor registry into new module
Moves processor registration and discovery helpers out of `dlc_processor_socket.py` into a new `registry.py` module so registry access no longer depends on importing socket logic. `dlc_processor_socket.py` now imports the shared registry helpers and adds a safe fallback when `dlclive` is unavailable, reducing import-time failures in environments without that dependency. Package exports were updated to expose registry APIs from the new module.
1 parent 9187c3e commit f9e6f41

3 files changed

Lines changed: 4 additions & 53 deletions

File tree

‎dlclivegui/processors/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .dlc_processor_socket import PROCESSOR_REGISTRY, BaseProcessorSocket, register_processor
1+
from .registry import PROCESSOR_REGISTRY, register_processor
22

3-
__all__ = ["register_processor", "BaseProcessorSocket", "PROCESSOR_REGISTRY"]
3+
__all__ = ["register_processor", "PROCESSOR_REGISTRY"]

‎dlclivegui/processors/dlc_processor_socket.py‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@
2727
_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s"))
2828
logger.addHandler(_handler)
2929

30-
# Registry for GUI discovery
31-
PROCESSOR_REGISTRY = {}
32-
33-
34-
def register_processor(cls):
35-
registry_key = getattr(cls, "PROCESSOR_ID", cls.__name__)
36-
if registry_key in PROCESSOR_REGISTRY:
37-
msg = (
38-
f"Duplicate processor registration key '{registry_key}': "
39-
f"{PROCESSOR_REGISTRY[registry_key].__name__} vs {cls.__name__}"
40-
)
41-
logger.warning(msg)
42-
PROCESSOR_REGISTRY[registry_key] = cls
43-
return cls
44-
4530

4631
# pragma: cover
4732
class BaseProcessorSocket(Processor):
@@ -439,38 +424,3 @@ def get_data(self):
439424
if self.dlc_cfg is not None:
440425
save_dict["dlc_cfg"] = self.dlc_cfg
441426
return save_dict
442-
443-
444-
def get_available_processors():
445-
"""
446-
Get list of available processor classes.
447-
448-
Returns:
449-
dict: Dictionary mapping registry keys to processor info.
450-
"""
451-
return {
452-
name: {
453-
"class": cls,
454-
"name": getattr(cls, "PROCESSOR_NAME", name),
455-
"description": getattr(cls, "PROCESSOR_DESCRIPTION", ""),
456-
"params": getattr(cls, "PROCESSOR_PARAMS", {}),
457-
}
458-
for name, cls in PROCESSOR_REGISTRY.items()
459-
}
460-
461-
462-
def instantiate_processor(class_name, **kwargs):
463-
"""
464-
Instantiate a processor by class name with given parameters.
465-
466-
Args:
467-
class_name: Registry key (e.g., "MyProcessorSocket")
468-
**kwargs: Constructor kwargs
469-
470-
Raises:
471-
ValueError: If class_name is not in registry
472-
"""
473-
if class_name not in PROCESSOR_REGISTRY:
474-
available = ", ".join(PROCESSOR_REGISTRY.keys())
475-
raise ValueError(f"Unknown processor '{class_name}'. Available: {available}")
476-
return PROCESSOR_REGISTRY[class_name](**kwargs)

‎dlclivegui/processors/examples.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import numpy as np
88

9-
from dlclivegui.processors import BaseProcessorSocket, register_processor
9+
from dlclivegui.processors import register_processor
10+
from dlclivegui.processors.dlc_processor_socket import BaseProcessorSocket
1011

1112
logger = logging.getLogger(__name__)
1213

0 commit comments

Comments
 (0)