From 3b39e0f19355b1e0f036b196b125cb7a36a7e64e Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Mon, 20 Jan 2014 15:39:13 +0100 Subject: [PATCH 1/3] Test plugin commands from plugin paths --- test/rsrc/beetsplug/test.py | 11 +++++++++++ test/test_ui.py | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 test/rsrc/beetsplug/test.py 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..9b77a83ea 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'] = [_common.RSRC] + config['plugins'] = ['test'] + ui._raw_main(['test']) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From a4b69767553ebc6c2447787ec9d0263050830f71 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Mon, 20 Jan 2014 17:34:37 +0100 Subject: [PATCH 2/3] Make plugin path configuration useable --- beets/ui/__init__.py | 4 +++- docs/reference/config.rst | 10 +++++----- test/test_ui.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 488974dee..af1b4b73f 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -746,7 +746,9 @@ def _raw_main(args): from beets.ui.commands import default_commands # Add plugin paths. - sys.path += get_plugin_paths() + import beetsplug + beetsplug.__path__ = get_plugin_paths() + beetsplug.__path__ + # 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/test_ui.py b/test/test_ui.py index 9b77a83ea..041021d80 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -668,7 +668,7 @@ class PathFormatTest(_common.TestCase): class PluginTest(_common.TestCase): def test_plugin_command_from_pluginpath(self): - config['pluginpath'] = [_common.RSRC] + config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')] config['plugins'] = ['test'] ui._raw_main(['test']) From 712358fab47f8ee9cda407bbeb03d7b320d85d48 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Tue, 21 Jan 2014 01:07:52 +0100 Subject: [PATCH 3/3] Keep old pluginpath mechanism for compatibility --- beets/ui/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index af1b4b73f..621f150ee 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -749,6 +749,9 @@ def _raw_main(args): 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")