Passed
Pull Request — master (#33)
by Konstantinos
02:17
created

so_magic.data.backend.engine.Engine.backend()   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
"""Define a wrapper around an Engine as the Backend class which constructor can initialize Backend instances."""
2
import attr
3
from so_magic.data.datapoints_manager import DatapointsManager
4
from so_magic.data.backend.panda_handling.df_backend import magic_backends
5
6
7
@attr.s
8
class Engine:
9
    """Wrapper of a data engine, a datapoints manager and a datapoints factory.
10
11
    Instances of this class act as data placeholders (aka data classes) and take at runtime a data engine (eg a set of
12
    pandas-dependent implementations of the "Tabular Data interfaces" defined in so_magic.data.interfaces).
13
14
    Args:
15
        engine_instance (DataEngine): a data engine represented as a class object (eg class MyClass: pass)
16
    """
17
    backend_instance = attr.ib(init=True)
18
    backends = attr.ib(init=True, default=attr.Factory(magic_backends))
19
    datapoints_manager = attr.ib(init=False, default=attr.Factory(DatapointsManager))
20
21
    @property
22
    def backend(self):
23
        """The Data Engine instance, that this object wraps around.
24
25
        Returns:
26
            DataEngine: the Data Engine instance object
27
        """
28
        return self.backend_instance
29
30
    @backend.setter
31
    def backend(self, engine):
32
        """Set the Data Engine instance to the input engine object.
33
34
        Args:
35
            engine (DataEngine): the Data Engine object to set with
36
        """
37
        self.backend_instance = engine
38
39
    @staticmethod
40
    def from_backend(backend_id: str):
41
        engine = Engine(None)
42
        engine.backend = engine.backends.backends[backend_id]
43
        return engine
44