summaryrefslogtreecommitdiff
path: root/buildstream/_plugincontext.py
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-08-29 22:24:33 -0400
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-08-29 22:32:15 -0400
commitbadbda8e81ee0584d81eecbf111e3a3ae3d76967 (patch)
tree8ce3f6a506b61fa6e053c60985c7e8acb5d88db7 /buildstream/_plugincontext.py
parent3cc9e191b83526cea757f92b522e3e8b1359d6eb (diff)
downloadbuildstream-badbda8e81ee0584d81eecbf111e3a3ae3d76967.tar.gz
_plugincontext.py: Load plugins on demand
This fixes issue #79
Diffstat (limited to 'buildstream/_plugincontext.py')
-rw-r--r--buildstream/_plugincontext.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/buildstream/_plugincontext.py b/buildstream/_plugincontext.py
index 9f3bd4d02..7b54ddc15 100644
--- a/buildstream/_plugincontext.py
+++ b/buildstream/_plugincontext.py
@@ -44,10 +44,13 @@ class PluginContext():
raise PluginError("Cannot create plugin context without any searchpath")
self.base_type = base_type # The base class plugins derive from
- self.source = None # The PluginSource object
self.types = {} # Plugin type lookup table by kind
- self.load_plugins(plugin_base, searchpath)
+ # Raise an error if we have more than one plugin with the same name
+ self.assert_searchpath(searchpath)
+
+ # The PluginSource object
+ self.source = plugin_base.make_plugin_source(searchpath=searchpath)
# lookup():
#
@@ -61,21 +64,18 @@ class PluginContext():
# Raises: PluginError
#
def lookup(self, kind):
- if kind not in self.types:
- raise PluginError("No %s type registered for kind '%s'" %
- (self.base_type.__name__, kind))
-
- return self.types[kind]
+ return self.ensure_plugin(kind)
- def load_plugins(self, base, searchpath):
+ def ensure_plugin(self, kind):
- # Raise an error if we have more than one plugin with the same name
- self.assert_searchpath(searchpath)
-
- self.source = base.make_plugin_source(searchpath=searchpath)
- for kind in self.source.list_plugins():
+ if kind not in self.types:
+ if kind not in self.source.list_plugins():
+ raise PluginError("No %s type registered for kind '%s'" %
+ (self.base_type.__name__, kind))
self.load_plugin(kind)
+ return self.types[kind]
+
def load_plugin(self, kind):
plugin = self.source.load_plugin(kind)