archangelic / pinhook

the pluggable python framework for IRC bots and Twitch bots
https://archangelic.github.io/pinhook/
MIT License
31 stars 4 forks source link

!reload does not reload plugin dependencies #42

Closed RussellChamp closed 5 years ago

RussellChamp commented 5 years ago

I treat my plugin files as thin shims that just import util methods. Running a !reload against bot commands will reload the plugin file but not plugin dependencies. Eg. I might have "./plugins/foo.py" that contains from util import doFoo. Running a !reload will reload "foo.py" but not my "doFoo" module. In order to reload the "doFoo" module, I need to do a full bot restart.

Cheers!

archangelic commented 5 years ago

Looks like this bug would be fixed by doing the work needed to change from imp to importlib (#6)

archangelic commented 5 years ago

This seems to be an issue with the way reimporting works in general. Still going to change out imp in favor of importlib.

from https://docs.python.org/3/library/importlib.html#importlib.reload

If a module imports objects from another module using from … import …, calling reload() for the other module does not redefine the objects imported from it — one way around this is to re-execute the from statement, another is to use import and qualified names (module.name) instead.

Please change your import statements to work this way as I cannot change this.

MineRobber9000 commented 5 years ago

Further, if you can't figure out to make it work (since mine still doesn't work), just adding:

import util
reload(util)
doFoo = util.doFoo

or something similar should work (import the module, clear cache, grab what you need of it.