aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/apps/_loader.py
blob: 36dd8a6f3aee2544a37c3acdc124d31734ca1d58 (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

# 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 ##