I am developing a slack bot with plugins using entry points. I want to dynamically add a plugin during runtime.
I have a project with this structure:
+ ~/my_project_dir/
+ my_projects_python_code/
+ plugins/
- plugin1.py
- plugin2.py
- ...
- pluginN.py
- setup.py
- venv/
- install.sh
My setup.py
file looks like this:
from setuptools import setup, find_packages
setup(
name="My_Project_plugins",
version="1.0",
packages=['plugins'],
entry_points="""
[my_project.plugins]
plugin1 = plugins.plugin1:plugin1_class
plugin2 = plugins.plugin2:plugin2_class
...
pluginN = plugins.pluginN:pluginN_class
"""
)
Running sudo install.sh
does the following:
Copies the needed files to
/usr/share/my_project_dir/
Activate virtualenv at
/usr/share/my_project_dir/venv/bin/activate
Run:
python setup.py develop
This works as expected and sets up my entry points correctly so that I can use them through the bot.
But I want to be able to add a plugin to setup.py
and be able to use it while the bot is running. So I want to add a line: pluginN+1 = plugins.pluginN+1:pluginN+1_class
and have pluginN+1 available to use.
What I've tried/learned:
After
/usr/share/my_project_dir/venv/bin/activate
I open a Python interactive shell and iterate throughpkg_resources.iter_entry_points()
, which lists everything that was loaded from the initial state of setup.py (i.e. plugin1 through pluginN)If I add a line to
setup.py
and runsudo python setup.py develop
and iterate again with the same Python shell, it doesn't pick up the new plugin but if I exit the shell and reopen it, the new plugin gets picked up.I noticed that when I install the bot, part of the output says:
Copying My_Project_plugins-1.0-py2.7.egg to /usr/share/my_project-dir/venv/lib/python2.7/site-packages
When I
cd /usr/share/my_project_dir/
, activate my virtualenv, and runsetup.py
from the shell it says:Creating /usr/local/lib/python2.7/dist-packages/My_Project-plugins.egg-link (link to .) My_Project-plugins 1.0 is already the active version in easy-install.pth