1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 12:06:08 +00:00

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)
This commit is contained in:
Douglas Raillard 2023-08-02 11:29:04 +01:00 committed by Marc Bonnici
parent 11374aae3f
commit d67d9bd2a4

View File

@ -622,19 +622,26 @@ class PluginLoader(object):
self.logger.debug('Checking path %s', path) self.logger.debug('Checking path %s', path)
if os.path.isfile(path): if os.path.isfile(path):
self._discover_from_file(path) self._discover_from_file(path)
for root, _, files in os.walk(path, followlinks=True): elif os.path.exists(path):
should_skip = False for root, _, files in os.walk(path, followlinks=True):
for igpath in ignore_paths: should_skip = False
if root.startswith(igpath): for igpath in ignore_paths:
should_skip = True if root.startswith(igpath):
break should_skip = True
if should_skip: break
continue if should_skip:
for fname in files:
if os.path.splitext(fname)[1].lower() != '.py':
continue continue
filepath = os.path.join(root, fname) for fname in files:
self._discover_from_file(filepath) 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: # NOQA pylint: disable=broad-except
pass
def _discover_from_file(self, filepath): def _discover_from_file(self, filepath):
try: try: