2 import importlib
.machinery
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
, '.']
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
):
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
):
21 module
= importlib
.util
.module_from_spec(spec
)
22 spec
.loader
.exec_module(module
)