From cf2833ee201e2750b1ba4a99eb6f34ad3b105207 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Tue, 16 Jun 2020 15:10:19 -0400 Subject: [PATCH] plugin: Load user configuration file. --- conservancy_beancount/plugin/__init__.py | 13 +++++++++++++ setup.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/conservancy_beancount/plugin/__init__.py b/conservancy_beancount/plugin/__init__.py index 13d1314..6f1cd8d 100644 --- a/conservancy_beancount/plugin/__init__.py +++ b/conservancy_beancount/plugin/__init__.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import importlib +import logging import beancount.core.data as bc_data @@ -42,11 +43,14 @@ from .core import ( HookName, ) from ..errors import ( + ConfigurationError, Error, ) __plugins__ = ['run'] +logger = logging.getLogger('conservancy_beancount.plugin') + class HookRegistry: INCLUDED_HOOKS: Dict[str, Optional[List[str]]] = { '.meta_approval': None, @@ -135,6 +139,15 @@ def run( t.__name__: [] for t in bc_data.ALL_DIRECTIVES # type:ignore[attr-defined] } user_config = configmod.Config() + try: + user_config.load_file() + except OSError as error: + logger.debug("error reading configuration file %s: %s", + error.filename, error.strerror, exc_info=True) + errors.append(ConfigurationError( + f"error reading configuration file {error.filename}: {error.strerror}", + source={'filename': error.filename}, + )) for key, hook_type in hook_registry.group_by_directive(config): try: hook = hook_type(user_config) diff --git a/setup.py b/setup.py index d2742fa..689a28a 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='conservancy_beancount', description="Plugin, library, and reports for reading Conservancy's books", - version='1.2.2', + version='1.2.3', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+',