-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfactories.py
48 lines (35 loc) · 1.21 KB
/
factories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from abc import ABC, abstractmethod
from typing import Dict
from exceptions import FileNotExists
from task import Task
class TaskFactory(ABC):
@staticmethod
@abstractmethod
def get_task(config: Dict):
pass
@staticmethod
@abstractmethod
def initialize_task(config: Dict):
pass
class DataLoadFactory(TaskFactory):
@staticmethod
def initialize_task(config: Dict):
# note that this can be split into classes or separate methods
# here you can do al preparations, make sure all libraries are imported
# if you want to import some libs only if a given task type is used etc.
if config.get('source') == 'csv':
if not os.path.isfile(config.get('task_params').get('path')):
raise FileNotExists("File with given path does not exists!")
@staticmethod
def get_task(config: Dict):
# here you actually return the task
DataLoadFactory.initialize_task(config)
return Task(config=config)
class DataTransformationFactory(TaskFactory):
@staticmethod
def initialize_task(config: Dict):
pass
@staticmethod
def get_task(config: Dict):
return Task(config=config)