aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/apps/_loader.py
blob: e02bed535bc20351a5d5c18f175e48b127fbfe0d (plain)
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
49
50
51
52
"""

Part of the bsie module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# standard imports
import typing

# external imports
import yaml

# bsie imports
from bsie.extractor import ExtractorBuilder
from bsie.lib import PipelineBuilder
from bsie.lib.pipeline import Pipeline
from bsie.reader import ReaderBuilder

# constants
DEFAULT_CONFIG_FILE = 'default_config.yaml'

# exports
__all__: typing.Sequence[str] = (
    'load',
    'DEFAULT_CONFIG_FILE',
    )


## code ##

def load_pipeline(path: str) -> Pipeline:
    """Load a pipeline according to a config at *path*."""
    # load config file
    with open(path, 'rt') as ifile:
        cfg = yaml.safe_load(ifile)

    # reader builder
    rbuild = ReaderBuilder(cfg['ReaderBuilder'])
    # extractor builder
    ebuild = ExtractorBuilder(cfg['ExtractorBuilder'])
    # pipeline builder
    pbuild = PipelineBuilder(
        rbuild,
        ebuild,
        )
    # build pipeline
    pipeline = pbuild.build()

    # return pipeline
    return pipeline

## EOF ##