[docs]classImmutableModel(pydantic.BaseModel):"""Specifies configurations for validating classes which objects should be immutable."""
[docs]classConfig:"""Configuration options for classes which objects are meant to be immutable."""arbitrary_types_allowed=Trueallow_mutation=Falsevalidate_all=Truesmart_union=Trueextra=Extra.ignorekeep_untouched=(cached_property,)
[docs]defserialize(self)->Any:"""Serialize the object. By defaults, this method raises a RuntimeError to notify the user that the method wasn't implemented. Raises: RuntimeError: Always. """raiseRuntimeError(f"{self.__class__.__name__}.serialize not implemented!")
[docs]@staticmethoddefdeserialize(self)->Any:"""Deserialize the object. By defaults, this method raises a RuntimeError to notify the user that the method wasn't implemented. Raises: RuntimeError: Always. """raiseRuntimeError(f"{self.__class__.__name__}.deserialize not implemented!")
[docs]classAlgorithm(abc.ABC):"""Base class of every node of the iris recognition pipeline."""
__parameters_type__=Parametersdef__init__(self,**kwargs:Any)->None:"""Init function."""self._callbacks:List[Callback]=[]if"callbacks"inkwargs.keys():self._callbacks=deepcopy(kwargs["callbacks"])delkwargs["callbacks"]self.params=self.__parameters_type__(**kwargs)def__call__(self,*args:Any,**kwargs:Any)->Any:"""Make an object a functor. Returns: Any: Object specified by an interface. """returnself.execute(*args,**kwargs)
[docs]defexecute(self,*args:Any,**kwargs:Any)->Any:"""Execute method and wrapped with hooks if such are specified. Returns: Any: Object specified by an interface. """forcallback_funcinself._callbacks:callback_func.on_execute_start(*args,**kwargs)result=self.run(*args,**kwargs)forcallback_funcinself._callbacks:callback_func.on_execute_end(result)returnresult
[docs]defrun(self,*args:Any,**kwargs:Any)->Any:"""Implement method design pattern. Not overwritten by subclass will raise an error. Raises: NotImplementedError: Raised if subclass doesn't implement `run` method. Returns: Any: Return value by concrate implementation of the `run` method. """raiseNotImplementedError(f"{self.__class__.__name__}.run method not implemented!")
[docs]definstantiate_class_from_name(class_name:str,kwargs:Dict[str,Any])->Any:"""Instantiate a class from its fully qualified name and keyword arguments. Args: class_name (str): Fully qualified name of the class to instantiate. kwargs (Dict[str, Any]): Keyword arguments to pass to the class constructor. Returns: Any: An instance of the located class. Raises: ValueError: If the class cannot be located by name. """object_class=pydoc.locate(class_name)ifobject_classisNone:raiseValueError(f"Could not locate class {class_name}")returnobject_class(**kwargs)