From ceae76423225fbf5355e775d7575c64f9d6951ee Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Wed, 2 Aug 2023 11:29:04 +0100 Subject: [PATCH] fw/plugin: Try to load plugin paths as Python module name WA_PLUGIN_PATHS currently contains a list of filesystem paths to scan for plugins. This is appropriate for end-user plugins, but this is problematic for plugins distributed by a 3rd party, such as a plugin installed from PyPI. In those cases, the path to the sources is unknown and typically depends on the specify Python version, local setup etc. What is constant is Python name of the package, e.g. "lisa.wa.plugins". Extend the input allowed in WA_PLUGIN_PATHS by trying to load entries as a Python package name if: * There is no filesystem path with that name * The entry is a "relative path" (from an fs point of view) --- wa/framework/plugin.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/wa/framework/plugin.py b/wa/framework/plugin.py index 6c00ef6f6..68d47e6ec 100644 --- a/wa/framework/plugin.py +++ b/wa/framework/plugin.py @@ -622,19 +622,26 @@ def _discover_from_paths(self, paths, ignore_paths): self.logger.debug('Checking path %s', path) if os.path.isfile(path): self._discover_from_file(path) - for root, _, files in os.walk(path, followlinks=True): - should_skip = False - for igpath in ignore_paths: - if root.startswith(igpath): - should_skip = True - break - if should_skip: - continue - for fname in files: - if os.path.splitext(fname)[1].lower() != '.py': + elif os.path.exists(path): + for root, _, files in os.walk(path, followlinks=True): + should_skip = False + for igpath in ignore_paths: + if root.startswith(igpath): + should_skip = True + break + if should_skip: continue - filepath = os.path.join(root, fname) - self._discover_from_file(filepath) + for fname in files: + if os.path.splitext(fname)[1].lower() != '.py': + continue + filepath = os.path.join(root, fname) + self._discover_from_file(filepath) + elif not os.path.isabs(path): + try: + for module in walk_modules(path): + self._discover_in_module(module) + except Exception: + pass def _discover_from_file(self, filepath): try: