My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows:
plugin_name = blablabla
try:
module = __import__(plugin_name, fromlist='do_something')
except ImportError:
#some error handling ...
and then execute:
try:
loans = module.do_something(id_t, pin_t)
except xxx:
# error handling
I compile the application to a Windows binary using py2exe. This works fine, except for that the fact that all plugins are (and have to be) included in the binary. This is not very practical, since for each new plugin, I have to recompile and release a new version of my application. It would be better if a new plugin (i.e. python file) could be copied to some application plugin folder, and that the Python code in the file code be interpreted on-the-fly by my application.
What is the best approach to do so?
(I've though of reading each line of the selected plugin file, and applying an exec
statement to it. But there might be better ways...)