Browse Source

Refactor plugin loading

pull/227/head
Oliverpool 8 years ago
parent
commit
1ed28ef2b4
  1. 8
      patacrep/build.py
  2. 17
      patacrep/files.py
  3. 7
      patacrep/tools/convert/__main__.py
  4. 8
      test/test_content/test_content.py
  5. 4
      test/test_song/test_parser.py

8
patacrep/build.py

@ -80,15 +80,11 @@ class Songbook:
)
# Loading custom plugins
self._config['_content_plugins'] = files.load_plugins(
self._config['_content_plugins'] = files.load_plugins_content(
datadirs=self._config['_datadir'],
root_modules=['content'],
keyword='CONTENT_PLUGINS',
)
self._config['_song_plugins'] = files.load_plugins(
self._config['_song_plugins'] = files.load_plugins_songs(
datadirs=self._config['_datadir'],
root_modules=['songs'],
keyword='SONG_RENDERERS',
)['tsg']
# Configuration set

17
patacrep/files.py

@ -93,6 +93,22 @@ def iter_modules(path, prefix):
LOGGER.debug("[plugins] Could not load module {}: {}".format(name, str(error)))
continue
def load_plugins_content(datadirs=()):
"""Load the content plugins, and return a dictionary of those plugins."""
return load_plugins(
datadirs=datadirs,
root_modules=('content',),
keyword='CONTENT_PLUGINS',
)
def load_plugins_songs(datadirs=()):
"""Load the song renderer plugins, and return a dictionary of those plugins."""
return load_plugins(
datadirs=datadirs,
root_modules=('songs',),
keyword='SONG_RENDERERS',
)
def load_plugins(datadirs, root_modules, keyword):
"""Load all plugins, and return a dictionary of those plugins.
@ -102,6 +118,7 @@ def load_plugins(datadirs, root_modules, keyword):
Arguments:
- datadirs: List of directories in which plugins are to be searched.
The plugins will also be searched in the patacrep modules.
- root_modules: the submodule in which plugins are to be searched, as a
list of modules (e.g. ["some", "deep", "module"] for
"some.deep.module").

7
patacrep/tools/convert/__main__.py

@ -35,12 +35,7 @@ def main(args=None):
dest = args[2]
song_files = args[3:]
# todo : what is the datadir argument used for?
renderers = files.load_plugins(
datadirs=[],
root_modules=['songs'],
keyword='SONG_RENDERERS',
)
renderers = files.load_plugins_songs()
if dest not in renderers:
LOGGER.error(

8
test/test_content/test_content.py

@ -108,15 +108,11 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
)
# Load the plugins
config['_content_plugins'] = files.load_plugins(
config['_content_plugins'] = files.load_plugins_content(
datadirs=config['_datadir'],
root_modules=['content'],
keyword='CONTENT_PLUGINS',
)
config['_song_plugins'] = files.load_plugins(
config['_song_plugins'] = files.load_plugins_songs(
datadirs=config['_datadir'],
root_modules=['songs'],
keyword='SONG_RENDERERS',
)['tsg']
return config

4
test/test_song/test_parser.py

@ -81,10 +81,8 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
cls.config['_datadir'] = []
cls.config['_datadir'].append('datadir')
cls.song_plugins = files.load_plugins(
cls.song_plugins = files.load_plugins_songs(
datadirs=cls.config['_datadir'],
root_modules=['songs'],
keyword='SONG_RENDERERS',
)
with cls.chdir():
for source in sorted(glob.glob('*.*.source')):

Loading…
Cancel
Save