summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2017-10-12 15:30:58 +0100
committerTristan Maat <tristan.maat@codethink.co.uk>2017-10-12 16:15:28 +0100
commit85c1a8bcfab764d780b21069f656061a2b2faf28 (patch)
tree1d0e31c53f187c649ce09ccd4bf785802330f525
parenta580a4a032c2e492c5287a976ced1db178467549 (diff)
downloadbuildstream-external_plugin_errors.tar.gz
_plugincontext.py: Fix third party plugin loadingexternal_plugin_errors
-rw-r--r--buildstream/_plugincontext.py43
1 files changed, 28 insertions, 15 deletions
diff --git a/buildstream/_plugincontext.py b/buildstream/_plugincontext.py
index e725211a9..0207136ef 100644
--- a/buildstream/_plugincontext.py
+++ b/buildstream/_plugincontext.py
@@ -58,6 +58,7 @@ class PluginContext():
# The PluginSource object
self.plugin_base = plugin_base
self.source = plugin_base.make_plugin_source(searchpath=searchpath)
+ self.alternate_sources = []
# lookup():
#
@@ -85,21 +86,33 @@ class PluginContext():
# potentially unpacks the file and puts it in a
# temporary directory, but it is otherwise guaranteed
# to exist.
- plugin = pkg_resources.get_entry_info(dist, 'buildstream.plugins', package)
- location = plugin.dist.get_resource_filename(
- pkg_resources._manager,
- plugin.module_name.replace('.', os.sep) + '.py'
- )
-
- # Also load the defaults - required since setuptools
- # may need to extract the file.
- defaults = plugin.dist.get_resource_filename(
- pkg_resources._manager,
- plugin.module_name.replace('.', os.sep) + '.yaml'
- )
-
- # Set the plugin-base source to the setuptools directory
- source = self.plugin_base.make_plugin_source(searchpath=[os.path.dirname(location)])
+ try:
+ plugin = pkg_resources.get_entry_info(dist, 'buildstream.plugins', package)
+ except pkg_resources.DistributionNotFound as e:
+ raise PluginError("Failed to load {} plugin '{}': {}"
+ .format(self.base_type.__name__, kind, e)) from e
+
+ # Missing plugins will return as 'None'
+ if plugin is not None:
+ location = plugin.dist.get_resource_filename(
+ pkg_resources._manager,
+ plugin.module_name.replace('.', os.sep) + '.py'
+ )
+
+ # Also load the defaults - required since setuptools
+ # may need to extract the file.
+ defaults = plugin.dist.get_resource_filename(
+ pkg_resources._manager,
+ plugin.module_name.replace('.', os.sep) + '.yaml'
+ )
+
+ # Set the plugin-base source to the setuptools directory
+ source = self.plugin_base.make_plugin_source(searchpath=[os.path.dirname(location)])
+ # Ensure the plugin sources aren't garbage
+ # collected - if they are, they take any loaded
+ # plugins with them, regardless of whether those
+ # have remaining references or not.
+ self.alternate_sources.append(source)
elif package in self.source.list_plugins():
source = self.source