From 464cc6cb54f55f6255bf0a485533c181d6018303 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Wed, 1 Mar 2023 17:07:06 +0100 Subject: load config from file --- bsie/apps/_loader.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 bsie/apps/_loader.py (limited to 'bsie/apps/_loader.py') 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 ## -- cgit v1.2.3 From 4b5c4d486bb4f0f4da2e25ad464e8336a781cdcb Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Wed, 1 Mar 2023 22:31:03 +0100 Subject: removed module header stubs --- bsie/apps/_loader.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'bsie/apps/_loader.py') diff --git a/bsie/apps/_loader.py b/bsie/apps/_loader.py index e02bed5..36dd8a6 100644 --- a/bsie/apps/_loader.py +++ b/bsie/apps/_loader.py @@ -1,9 +1,4 @@ -""" -Part of the bsie module. -A copy of the license is provided with the project. -Author: Matthias Baumgartner, 2022 -""" # standard imports import typing -- cgit v1.2.3 From ba6329bbe14c832d42773dee2fe30bd7669ca255 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Thu, 2 Mar 2023 08:58:29 +0100 Subject: various minor fixes --- bsie/apps/_loader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bsie/apps/_loader.py') diff --git a/bsie/apps/_loader.py b/bsie/apps/_loader.py index 36dd8a6..6411f10 100644 --- a/bsie/apps/_loader.py +++ b/bsie/apps/_loader.py @@ -16,8 +16,8 @@ DEFAULT_CONFIG_FILE = 'default_config.yaml' # exports __all__: typing.Sequence[str] = ( - 'load', 'DEFAULT_CONFIG_FILE', + 'load_pipeline', ) @@ -26,7 +26,7 @@ __all__: typing.Sequence[str] = ( def load_pipeline(path: str) -> Pipeline: """Load a pipeline according to a config at *path*.""" # load config file - with open(path, 'rt') as ifile: + with open(path, 'rt', encoding='utf-8') as ifile: cfg = yaml.safe_load(ifile) # reader builder -- cgit v1.2.3