diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-03-01 17:07:06 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-03-01 17:07:06 +0100 |
commit | 464cc6cb54f55f6255bf0a485533c181d6018303 (patch) | |
tree | 0a2447aac75d91230b4fdbaddf129d408e5d5b7e /bsie/apps/_loader.py | |
parent | 02cd75f31120a766a35fc0ae00f8d0711c1c0ae9 (diff) | |
download | bsie-464cc6cb54f55f6255bf0a485533c181d6018303.tar.gz bsie-464cc6cb54f55f6255bf0a485533c181d6018303.tar.bz2 bsie-464cc6cb54f55f6255bf0a485533c181d6018303.zip |
load config from file
Diffstat (limited to 'bsie/apps/_loader.py')
-rw-r--r-- | bsie/apps/_loader.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/bsie/apps/_loader.py b/bsie/apps/_loader.py new file mode 100644 index 0000000..e02bed5 --- /dev/null +++ b/bsie/apps/_loader.py @@ -0,0 +1,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 ## |