diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-10-12 15:30:58 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-10-13 17:35:40 +0900 |
commit | 58a1dd4ba9aef43a47d7dd24deee6eb9e9e45b30 (patch) | |
tree | 0ef4fad057d558def7b86741c4c4018fd46d274c /buildstream/_plugincontext.py | |
parent | 446875be50996de0c1447af43de75d1f7b037219 (diff) | |
download | buildstream-58a1dd4ba9aef43a47d7dd24deee6eb9e9e45b30.tar.gz |
_plugincontext.py: Fix third party plugin loading
Diffstat (limited to 'buildstream/_plugincontext.py')
-rw-r--r-- | buildstream/_plugincontext.py | 43 |
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 |