aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/apps/_loader.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsie/apps/_loader.py')
-rw-r--r--bsie/apps/_loader.py52
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 ##