From f2ab2bac6b26f82730d5f5d7ab1e6d5f2f1060e3 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sun, 19 Feb 2023 23:36:04 -0600 Subject: add yaml_parser tests, small refactor --- src/pyssg/__init__.py | 2 ++ src/pyssg/yaml_parser.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pyssg/__init__.py b/src/pyssg/__init__.py index 5d112f1..46e2323 100644 --- a/src/pyssg/__init__.py +++ b/src/pyssg/__init__.py @@ -1,7 +1,9 @@ from .pyssg import main from .custom_logger import setup_logger +from .yaml_parser import setup_custom_yaml setup_logger() +setup_custom_yaml() # not meant to be used as a package, so just give main __all__ = ['main'] diff --git a/src/pyssg/yaml_parser.py b/src/pyssg/yaml_parser.py index fb19a23..2e1548b 100644 --- a/src/pyssg/yaml_parser.py +++ b/src/pyssg/yaml_parser.py @@ -13,6 +13,10 @@ def __join_constructor(loader: SafeLoader, node: SequenceNode) -> str: return ''.join([str(i) for i in seq]) +def setup_custom_yaml() -> None: + SafeLoader.add_constructor('!join', __join_constructor) + + def __read_raw_yaml(path: str) -> list[dict]: all_docs: list[dict] = [] with open(path, 'r') as f: @@ -28,6 +32,3 @@ def get_parsed_yaml(resource: str, package: str = '') -> list[dict]: log.debug('parsing yaml; reading "%s.%s"', package, resource) with rpath(package, resource) as p: return __read_raw_yaml(str(p)) - - -SafeLoader.add_constructor('!join', __join_constructor) -- cgit v1.2.3-70-g09d2