from abc import ABC, abstractmethod
from typing import Tuple
from .transport import TransportableObject
class Deps(ABC):
"""Generic dependency class used in specifying any kind of dependency for an electron.
Attributes:
apply_fn: function to be executed in the backend environment
apply_args: list of arguments to be applied in the backend environment
apply_kwargs: dictionary of keyword arguments to be applied in the backend environment
"""
def __init__(self, apply_fn=None, apply_args=[], apply_kwargs={}, *, retval_keyword=""):
self.apply_fn = TransportableObject(apply_fn)
self.apply_args = TransportableObject(apply_args)
self.apply_kwargs = TransportableObject(apply_kwargs)
self.retval_keyword = retval_keyword
def apply(self) -> Tuple[TransportableObject, TransportableObject, TransportableObject, str]:
"""
Encapsulates the exact function and args/kwargs to be executed in the backend environment.
Args:
None
Returns:
A tuple of transportable objects containing the function and optional args/kwargs
"""
return (self.apply_fn, self.apply_args, self.apply_kwargs, self.retval_keyword)
def short_name(self):
return self.__module__.split("/")[-1].split(".")[-1]
@abstractmethod
def to_dict(self):
raise NotImplementedError
@abstractmethod
def from_dict(self, object_dict):
raise NotImplementedError