From 9c9e4609a87d40257f8b3e7517857fdde1d214fb Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sun, 12 Jun 2016 22:09:34 +0200 Subject: [PATCH] Automatically load content plugins --- patacrep/build.py | 4 ---- patacrep/content/__init__.py | 2 +- patacrep/files.py | 6 ++++-- test/test_content/test_content.py | 3 --- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/patacrep/build.py b/patacrep/build.py index a1ece8a5..1cc4a42a 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -79,10 +79,6 @@ class Songbook: copy.deepcopy(self._config['authors']) ) - # Loading custom plugins - self._config['_content_plugins'] = files.load_plugins_content( - datadirs=self._config['_datadir'], - ) self._config['_song_plugins'] = files.load_plugins_songs( datadirs=self._config['_datadir'], )['tsg'] diff --git a/patacrep/content/__init__.py b/patacrep/content/__init__.py index a65b0525..9b0655af 100755 --- a/patacrep/content/__init__.py +++ b/patacrep/content/__init__.py @@ -259,7 +259,7 @@ def process_content(content, config=None): included in the .tex file. """ contentlist = ContentList() - plugins = config.get('_content_plugins', {}) + plugins = files.load_plugins_content(config['_datadir']) if not content: content = [{'song': None}] elif isinstance(content, dict): diff --git a/patacrep/files.py b/patacrep/files.py index 8a3963ec..bad0f90f 100644 --- a/patacrep/files.py +++ b/patacrep/files.py @@ -1,6 +1,7 @@ """File system utilities.""" from contextlib import contextmanager +from functools import lru_cache import logging import os import pkgutil @@ -96,7 +97,7 @@ def iter_modules(path, prefix): def load_plugins_content(datadirs=()): """Load the content plugins, and return a dictionary of those plugins.""" return load_plugins( - datadirs=datadirs, + datadirs=tuple(datadirs), root_modules=('content',), keyword='CONTENT_PLUGINS', ) @@ -104,11 +105,12 @@ def load_plugins_content(datadirs=()): def load_plugins_songs(datadirs=()): """Load the song renderer plugins, and return a dictionary of those plugins.""" return load_plugins( - datadirs=datadirs, + datadirs=tuple(datadirs), root_modules=('songs',), keyword='SONG_RENDERERS', ) +@lru_cache() def load_plugins(datadirs, root_modules, keyword): """Load all plugins, and return a dictionary of those plugins. diff --git a/test/test_content/test_content.py b/test/test_content/test_content.py index 3c675889..0a28ea69 100644 --- a/test/test_content/test_content.py +++ b/test/test_content/test_content.py @@ -108,9 +108,6 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): ) # Load the plugins - config['_content_plugins'] = files.load_plugins_content( - datadirs=config['_datadir'], - ) config['_song_plugins'] = files.load_plugins_songs( datadirs=config['_datadir'], )['tsg']