'''
Meta class to auto register new classes with sqlalchemy bases
'''
[docs]__author__ = 'Elisha Yadgaran'
from abc import ABCMeta
from sqlalchemy.ext.declarative import declarative_base
from simpleml.registries.registry import Registry
# Importable registry
# Instantiate specific persistable registries for easy lookup of object types
# NEED to use consistent import pattern, otherwise will refer to different memory objects
# from meta_register import SIMPLEML_REGISTRY as s1 != from simpleml.persistables.meta_register import SIMPLEML_REGISTRY as s2
[docs]SIMPLEML_REGISTRY = Registry()
[docs]DATASET_REGISTRY = Registry()
[docs]PIPELINE_REGISTRY = Registry()
[docs]MODEL_REGISTRY = Registry()
[docs]METRIC_REGISTRY = Registry()
# Need to explicitly merge metaclasses to avoid conflicts
[docs]class DatasetRegistry(MetaRegistry):
def __new__(cls, clsname, bases, attrs):
newclass = super(DatasetRegistry, cls).__new__(cls, clsname, bases, attrs)
DATASET_REGISTRY.register(newclass)
return newclass
[docs]class PipelineRegistry(MetaRegistry):
def __new__(cls, clsname, bases, attrs):
newclass = super(PipelineRegistry, cls).__new__(cls, clsname, bases, attrs)
PIPELINE_REGISTRY.register(newclass)
return newclass
[docs]class ModelRegistry(MetaRegistry):
def __new__(cls, clsname, bases, attrs):
newclass = super(ModelRegistry, cls).__new__(cls, clsname, bases, attrs)
MODEL_REGISTRY.register(newclass)
return newclass
[docs]class MetricRegistry(MetaRegistry):
def __new__(cls, clsname, bases, attrs):
newclass = super(MetricRegistry, cls).__new__(cls, clsname, bases, attrs)
METRIC_REGISTRY.register(newclass)
return newclass