diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 488974dee..621f150ee 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -746,7 +746,12 @@ def _raw_main(args): from beets.ui.commands import default_commands # Add plugin paths. + import beetsplug + beetsplug.__path__ = get_plugin_paths() + beetsplug.__path__ + + # For backwards compatibility sys.path += get_plugin_paths() + # Load requested plugins. plugins.load_plugins(config['plugins'].as_str_seq()) plugins.send("pluginload") diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 482f51e2f..c61d46784 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -55,11 +55,11 @@ includes the BPD plugin for playing music. pluginpath ~~~~~~~~~~ -Directories to search for plugins. These paths are just added to ``sys.path`` -before the plugins are loaded. (The plugins still have to be contained in a -``beetsplug`` namespace package.) This can either be a single string or a list -of strings---so, if you have multiple paths, format them as a YAML list like -so:: +Directories to search for plugins. Each Python file or directory in a plugin +path represents a plugin and should define a subclass of :class:`BeetsPlugin`. +A plugin can then be loaded by adding the filename to the `plugins` configuration. +The plugin path can either be a single string or a list of strings---so, if you +have multiple paths, format them as a YAML list like so:: pluginpath: - /path/one diff --git a/test/rsrc/beetsplug/test.py b/test/rsrc/beetsplug/test.py new file mode 100644 index 000000000..296d522ed --- /dev/null +++ b/test/rsrc/beetsplug/test.py @@ -0,0 +1,11 @@ +from beets.plugins import BeetsPlugin +from beets import ui + +class TestPlugin(BeetsPlugin): + def __init__(self): + super(TestPlugin, self).__init__() + + def commands(self): + cmd = ui.Subcommand('test') + cmd.func = lambda *args: None + return [cmd] diff --git a/test/test_ui.py b/test/test_ui.py index b6c13fb7f..041021d80 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -666,6 +666,12 @@ class PathFormatTest(_common.TestCase): self.assertEqual(tmpl.original, 'bar') self.assertEqual(pf[1:], default_formats) +class PluginTest(_common.TestCase): + def test_plugin_command_from_pluginpath(self): + config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')] + config['plugins'] = ['test'] + ui._raw_main(['test']) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)