diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-09-12 14:10:07 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-09-14 14:36:32 -0400 |
commit | 032d0f3bbc337663576fdeee70f6a49e66f836c8 (patch) | |
tree | a0b9180d2f0c632eb845936e7dc73ec26ebc7406 /buildstream/_plugincontext.py | |
parent | 6a326f465888fbf411682dd6c7c58cc7bc597e6b (diff) | |
download | buildstream-032d0f3bbc337663576fdeee70f6a49e66f836c8.tar.gz |
Add support for YAML default config loading
Diffstat (limited to 'buildstream/_plugincontext.py')
-rw-r--r-- | buildstream/_plugincontext.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/buildstream/_plugincontext.py b/buildstream/_plugincontext.py index 8c208af48..96ee2e2c5 100644 --- a/buildstream/_plugincontext.py +++ b/buildstream/_plugincontext.py @@ -75,6 +75,7 @@ class PluginContext(): if kind not in self.types: source = None + defaults = None dist, package = self.split_name(kind) if dist: @@ -88,6 +89,13 @@ class PluginContext(): 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)]) @@ -97,15 +105,21 @@ class PluginContext(): if not source: raise PluginError("No {} type registered for kind '{}'" .format(self.base_type.__name__, kind)) - self.types[kind] = self.load_plugin(source, package) + self.types[kind] = self.load_plugin(source, package, defaults) return self.types[kind] - def load_plugin(self, source, kind): + def load_plugin(self, source, kind, defaults): try: plugin = source.load_plugin(kind) + if not defaults: + plugin_file = inspect.getfile(plugin) + plugin_dir = os.path.dirname(plugin_file) + plugin_conf_name = "{}.yaml".format(kind) + defaults = os.path.join(plugin_dir, plugin_conf_name) + except ImportError as e: raise PluginError("Failed to load {} plugin '{}': {}" .format(self.base_type.__name__, kind, e)) from e @@ -121,7 +135,7 @@ class PluginContext(): self.assert_plugin(kind, plugin_type) self.assert_version(kind, plugin_type) - return plugin_type + return (plugin_type, defaults) def split_name(self, name): if name.count(':') > 1: |