diff options
author | Valentin David <valentin.david@codethink.co.uk> | 2018-07-18 11:37:31 +0200 |
---|---|---|
committer | Valentin David <valentin.david@codethink.co.uk> | 2018-08-02 16:17:01 +0200 |
commit | 19cd954bf9e22cbd6b7adacc9d87a693811830dc (patch) | |
tree | 07eec4174828f3e15821298e920ae91045f0c4c1 /buildstream/_plugincontext.py | |
parent | 483b0223bccad8c4c843d445f6621eefe2000744 (diff) | |
download | buildstream-19cd954bf9e22cbd6b7adacc9d87a693811830dc.tar.gz |
Refactor plugin factory creation
Diffstat (limited to 'buildstream/_plugincontext.py')
-rw-r--r-- | buildstream/_plugincontext.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/buildstream/_plugincontext.py b/buildstream/_plugincontext.py index 38d2231ba..5a7097485 100644 --- a/buildstream/_plugincontext.py +++ b/buildstream/_plugincontext.py @@ -20,7 +20,7 @@ import os import inspect -from ._exceptions import PluginError +from ._exceptions import PluginError, LoadError, LoadErrorReason from . import utils @@ -41,7 +41,9 @@ from . import utils # class PluginContext(): - def __init__(self, plugin_base, base_type, site_plugin_path, plugin_origins=None, dependencies=None): + def __init__(self, plugin_base, base_type, site_plugin_path, *, + plugin_origins=None, dependencies=None, + format_versions={}): # The plugin kinds which were loaded self.loaded_dependencies = [] @@ -58,6 +60,7 @@ class PluginContext(): self._plugin_base = plugin_base self._site_source = plugin_base.make_plugin_source(searchpath=site_plugin_path) self._alternate_sources = {} + self._format_versions = format_versions # lookup(): # @@ -219,3 +222,14 @@ class PluginContext(): self._base_type.__name__, kind, plugin_type.BST_REQUIRED_VERSION_MAJOR, plugin_type.BST_REQUIRED_VERSION_MINOR)) + + # _assert_plugin_format() + # + # Helper to raise a PluginError if the loaded plugin is of a lesser version then + # the required version for this plugin + # + def _assert_plugin_format(self, plugin, version): + if plugin.BST_FORMAT_VERSION < version: + raise LoadError(LoadErrorReason.UNSUPPORTED_PLUGIN, + "{}: Format version {} is too old for requested version {}" + .format(plugin, plugin.BST_FORMAT_VERSION, version)) |