diff options
author | Tristan van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-08-06 21:13:53 +0900 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-08-10 08:33:55 +0000 |
commit | 6798ea276cdabe668c3868253af9409663e85c46 (patch) | |
tree | 994b51d61a3242e12c900bc1b2f2fd2cc05fe850 | |
parent | cbc592b555212d49e1363a4e84d98551d4bf6826 (diff) | |
download | buildstream-6798ea276cdabe668c3868253af9409663e85c46.tar.gz |
_pluginfactory: Make list_plugins() report new display information
Now the PluginFactory.list_plugins() API also reports a human readable
explanation of where the plugin was loaded from for each plugin.
This is internally supported by an extension of the abstract
PluginOrigin.get_plugin_paths() APIs.
-rw-r--r-- | src/buildstream/_frontend/widget.py | 4 | ||||
-rw-r--r-- | src/buildstream/_pluginfactory/pluginfactory.py | 18 | ||||
-rw-r--r-- | src/buildstream/_pluginfactory/pluginorigin.py | 1 | ||||
-rw-r--r-- | src/buildstream/_pluginfactory/pluginoriginjunction.py | 9 | ||||
-rw-r--r-- | src/buildstream/_pluginfactory/pluginoriginlocal.py | 11 | ||||
-rw-r--r-- | src/buildstream/_pluginfactory/pluginoriginpip.py | 6 |
6 files changed, 31 insertions, 18 deletions
diff --git a/src/buildstream/_frontend/widget.py b/src/buildstream/_frontend/widget.py index 30b85701c..4c22723d6 100644 --- a/src/buildstream/_frontend/widget.py +++ b/src/buildstream/_frontend/widget.py @@ -486,8 +486,8 @@ class LogLine(Widget): # Plugins text += self._format_plugins( - [p for p, _, _ in project.element_factory.list_plugins()], - [p for p, _, _ in project.source_factory.list_plugins()], + [p for p, _, _, _ in project.element_factory.list_plugins()], + [p for p, _, _, _ in project.source_factory.list_plugins()], ) # Pipeline state diff --git a/src/buildstream/_pluginfactory/pluginfactory.py b/src/buildstream/_pluginfactory/pluginfactory.py index df950abee..f997d9017 100644 --- a/src/buildstream/_pluginfactory/pluginfactory.py +++ b/src/buildstream/_pluginfactory/pluginfactory.py @@ -165,10 +165,11 @@ class PluginFactory: # (str): The plugin kind # (type): The loaded plugin type # (str): The default yaml file, if any + # (str): The display string describing how the plugin was loaded # - def list_plugins(self) -> Iterator[Tuple[str, Type[Plugin], str]]: - for kind, (plugin_type, defaults) in self._types.items(): - yield kind, plugin_type, defaults + def list_plugins(self) -> Iterator[Tuple[str, Type[Plugin], str, str]]: + for kind, (plugin_type, defaults, display) in self._types.items(): + yield kind, plugin_type, defaults, display # get_plugin_paths(): # @@ -183,12 +184,13 @@ class PluginFactory: # (str): The full path to the directory containing the plugin # (str): The full path to the accompanying .yaml file containing # the plugin's preferred defaults. + # (str): The explanatory display string describing how this plugin was loaded # def get_plugin_paths(self, kind: str): try: origin = self._origins[kind] except KeyError: - return None, None + return None, None, None return origin.get_plugin_paths(kind, self._plugin_type) @@ -220,7 +222,7 @@ class PluginFactory: # the optional accompanying .yaml file for the plugin, should # one have been provided. # - location, defaults = self.get_plugin_paths(kind) + location, defaults, display = self.get_plugin_paths(kind) if location: @@ -245,10 +247,12 @@ class PluginFactory: defaults = os.path.join(self._site_plugins_path, "{}.yaml".format(kind)) if not os.path.exists(defaults): defaults = None + display = "core plugin" - self._types[kind] = (self._load_plugin(source, kind), defaults) + self._types[kind] = (self._load_plugin(source, kind), defaults, display) - return self._types[kind] + type_, defaults, _ = self._types[kind] + return type_, defaults # _load_plugin(): # diff --git a/src/buildstream/_pluginfactory/pluginorigin.py b/src/buildstream/_pluginfactory/pluginorigin.py index bd987171d..e75b8cb58 100644 --- a/src/buildstream/_pluginfactory/pluginorigin.py +++ b/src/buildstream/_pluginfactory/pluginorigin.py @@ -133,6 +133,7 @@ class PluginOrigin: # (str): The full path to the directory containing the plugin # (str): The full path to the accompanying .yaml file containing # the plugin's preferred defaults. + # (str): The explanatory display string describing how this plugin was loaded # def get_plugin_paths(self, kind, plugin_type): pass diff --git a/src/buildstream/_pluginfactory/pluginoriginjunction.py b/src/buildstream/_pluginfactory/pluginoriginjunction.py index 476f12c38..c32a7956c 100644 --- a/src/buildstream/_pluginfactory/pluginoriginjunction.py +++ b/src/buildstream/_pluginfactory/pluginoriginjunction.py @@ -48,7 +48,7 @@ class PluginOriginJunction(PluginOrigin): # Now ask for the paths from the subproject PluginFactory try: - location, defaults = factory.get_plugin_paths(kind) + location, defaults, display = factory.get_plugin_paths(kind) except PluginError as e: # Add some context to an error raised by loading a plugin from a subproject # @@ -74,7 +74,12 @@ class PluginOriginJunction(PluginOrigin): reason="junction-plugin-not-found", ) - return location, defaults + # Use the resolved project path for the display string rather than the user configured junction path + project_path = "toplevel project" + if project.junction: + project_path = project.junction._get_full_name() + + return location, defaults, "junction: {} ({})".format(project_path, display) def load_config(self, origin_node): diff --git a/src/buildstream/_pluginfactory/pluginoriginlocal.py b/src/buildstream/_pluginfactory/pluginoriginlocal.py index 5cfe2fd3a..34fba09e6 100644 --- a/src/buildstream/_pluginfactory/pluginoriginlocal.py +++ b/src/buildstream/_pluginfactory/pluginoriginlocal.py @@ -27,21 +27,20 @@ class PluginOriginLocal(PluginOrigin): def __init__(self): super().__init__(PluginOriginType.LOCAL) - # An absolute path to where plugins from this origin are found + # Project relative path to where plugins from this origin are found self._path = None def get_plugin_paths(self, kind, plugin_type): - defaults = os.path.join(self._path, "{}.yaml".format(kind)) + path = os.path.join(self.project.directory, self._path) + defaults = os.path.join(path, "{}.yaml".format(kind)) if not os.path.exists(defaults): defaults = None - return self._path, defaults + return path, defaults, "project directory: {}".format(self._path) def load_config(self, origin_node): origin_node.validate_keys(["path", *PluginOrigin._COMMON_CONFIG_KEYS]) path_node = origin_node.get_scalar("path") - path = self.project.get_path_from_node(path_node, check_is_dir=True) - - self._path = os.path.join(self.project.directory, path) + self._path = self.project.get_path_from_node(path_node, check_is_dir=True) diff --git a/src/buildstream/_pluginfactory/pluginoriginpip.py b/src/buildstream/_pluginfactory/pluginoriginpip.py index 3a9c63f7e..013cd67f3 100644 --- a/src/buildstream/_pluginfactory/pluginoriginpip.py +++ b/src/buildstream/_pluginfactory/pluginoriginpip.py @@ -89,7 +89,11 @@ class PluginOriginPip(PluginOrigin): # The plugin didn't have an accompanying YAML file defaults = None - return os.path.dirname(location), defaults + return ( + os.path.dirname(location), + defaults, + "python package '{}' at: {}".format(package.dist, package.dist.location), + ) def load_config(self, origin_node): |