Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable loading single module plugins #95

Merged
merged 1 commit into from
Feb 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions mmpy_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,25 @@ def init_plugins(self):
def _load_plugins(plugin):
logger.info('loading plugin "%s"', plugin)
path_name = None
# try to load root package as module first
PluginsManager._load_module(plugin)
# load modules in this plugin package
for mod in plugin.split('.'):
if path_name is not None:
path_name = [path_name]
_, path_name, _ = imp.find_module(mod, path_name)
for py_file in glob('{}/[!_]*.py'.format(path_name)):
module = '.'.join((plugin, os.path.split(py_file)[-1][:-3]))
try:
_module = importlib.import_module(module)
if hasattr(_module, 'on_init'):
_module.on_init()
except Exception as err:
logger.exception(err)
PluginsManager._load_module(module)

@staticmethod
def _load_module(module):
try:
_module = importlib.import_module(module)
if hasattr(_module, 'on_init'):
_module.on_init()
except Exception as err:
logger.exception(err)

def get_plugins(self, category, text):
has_matching_plugin = False
Expand Down