CI: Remove run-tests script
[fast-export.git] / pluginloader / __init__.py
blob529dbfbcf06ba0f49a2aa50eb0eedb0907bda01f
1 import os
2 import importlib.machinery
3 import importlib.util
4 PluginFolder = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","plugins")
5 MainModule = "__init__"
7 def get_plugin(name, plugin_path):
8 search_dirs = [PluginFolder, '.']
9 if plugin_path:
10 search_dirs = [plugin_path] + search_dirs
11 for dir in search_dirs:
12 location = os.path.join(dir, name)
13 if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location):
14 continue
15 spec = importlib.machinery.PathFinder.find_spec(MainModule, [location])
16 return {"name": name, "spec": spec, "path": location}
17 raise Exception("Could not find plugin with name " + name)
19 def load_plugin(plugin):
20 spec = plugin["spec"]
21 module = importlib.util.module_from_spec(spec)
22 spec.loader.exec_module(module)
23 return module