Browse Source

Automatically load content plugins

pull/227/head
Oliverpool 9 years ago
parent
commit
9c9e4609a8
  1. 4
      patacrep/build.py
  2. 2
      patacrep/content/__init__.py
  3. 6
      patacrep/files.py
  4. 3
      test/test_content/test_content.py

4
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']

2
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):

6
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.

3
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']

Loading…
Cancel
Save