plugin: Load user configuration file.
This commit is contained in:
parent
b1f82badf7
commit
cf2833ee20
2 changed files with 14 additions and 1 deletions
|
@ -15,6 +15,7 @@
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import logging
|
||||||
|
|
||||||
import beancount.core.data as bc_data
|
import beancount.core.data as bc_data
|
||||||
|
|
||||||
|
@ -42,11 +43,14 @@ from .core import (
|
||||||
HookName,
|
HookName,
|
||||||
)
|
)
|
||||||
from ..errors import (
|
from ..errors import (
|
||||||
|
ConfigurationError,
|
||||||
Error,
|
Error,
|
||||||
)
|
)
|
||||||
|
|
||||||
__plugins__ = ['run']
|
__plugins__ = ['run']
|
||||||
|
|
||||||
|
logger = logging.getLogger('conservancy_beancount.plugin')
|
||||||
|
|
||||||
class HookRegistry:
|
class HookRegistry:
|
||||||
INCLUDED_HOOKS: Dict[str, Optional[List[str]]] = {
|
INCLUDED_HOOKS: Dict[str, Optional[List[str]]] = {
|
||||||
'.meta_approval': None,
|
'.meta_approval': None,
|
||||||
|
@ -135,6 +139,15 @@ def run(
|
||||||
t.__name__: [] for t in bc_data.ALL_DIRECTIVES # type:ignore[attr-defined]
|
t.__name__: [] for t in bc_data.ALL_DIRECTIVES # type:ignore[attr-defined]
|
||||||
}
|
}
|
||||||
user_config = configmod.Config()
|
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):
|
for key, hook_type in hook_registry.group_by_directive(config):
|
||||||
try:
|
try:
|
||||||
hook = hook_type(user_config)
|
hook = hook_type(user_config)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ from setuptools import setup
|
||||||
setup(
|
setup(
|
||||||
name='conservancy_beancount',
|
name='conservancy_beancount',
|
||||||
description="Plugin, library, and reports for reading Conservancy's books",
|
description="Plugin, library, and reports for reading Conservancy's books",
|
||||||
version='1.2.2',
|
version='1.2.3',
|
||||||
author='Software Freedom Conservancy',
|
author='Software Freedom Conservancy',
|
||||||
author_email='info@sfconservancy.org',
|
author_email='info@sfconservancy.org',
|
||||||
license='GNU AGPLv3+',
|
license='GNU AGPLv3+',
|
||||||
|
|
Loading…
Reference in a new issue