summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2014-07-01 00:58:17 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2014-07-01 00:58:17 +0200
commitbb8da0bb60e0605efaf7e5093a6a7afa9898df0e (patch)
tree8e16e51e53e6c5d8e20b3d4b0b5242f35aa37ee7
parent51ad212d197146ce90f7a79c2eef16f85cdb2a47 (diff)
downloadpluginbase-bb8da0bb60e0605efaf7e5093a6a7afa9898df0e.tar.gz
Added an advanced example of discovery
-rw-r--r--docs/index.rst6
-rw-r--r--tests/plugins/advanced.py11
-rw-r--r--tests/test_advanced.py8
3 files changed, 22 insertions, 3 deletions
diff --git a/docs/index.rst b/docs/index.rst
index c4d4aec..a5c45e7 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -43,10 +43,10 @@ Step 3:
from yourapplication.plugins import my_plugin
my_plugin.do_something_cool()
-Alternatively you can also import plugins programmatically instead of
-using the import statement::
+ Alternatively you can also import plugins programmatically instead of
+ using the import statement::
- my_plugin = plugin_source.load_plugin('my_plugin')
+ my_plugin = plugin_source.load_plugin('my_plugin')
Installation
------------
diff --git a/tests/plugins/advanced.py b/tests/plugins/advanced.py
new file mode 100644
index 0000000..19eb051
--- /dev/null
+++ b/tests/plugins/advanced.py
@@ -0,0 +1,11 @@
+from pluginbase import get_plugin_source
+
+
+def get_app():
+ rv = get_plugin_source(stacklevel=1)
+ if rv is not None:
+ return rv.app
+
+
+def get_app_name():
+ return get_app().name
diff --git a/tests/test_advanced.py b/tests/test_advanced.py
new file mode 100644
index 0000000..d6440a5
--- /dev/null
+++ b/tests/test_advanced.py
@@ -0,0 +1,8 @@
+def test_custom_state(base):
+ class App(object):
+ name = 'foobar'
+ source = base.make_plugin_source(searchpath=['./plugins'])
+ source.app = App()
+
+ plg = source.load_plugin('advanced')
+ assert plg.get_app_name() == 'foobar'