# Copyright 2013 John Reese
# Licensed under the MIT license

import importlib
import os

from functools import lru_cache
from os import path

from .base import Plugin

@lru_cache()
def load_plugins(config):
    """Import all the plugins, and return a set of plugin instances, filtering
    out any plugin whose name appears in the configurable blacklist."""

    cwd = path.abspath(path.dirname(__file__))
    files = os.listdir(cwd)

    for filename in files:
        name, ext = path.splitext(filename)

        if name.startswith('_'):
            continue

        if ext == '.py':
            importlib.import_module('ircstat.plugins.' + name)

    plugins = set(plugin() for plugin in Plugin.subclasses())

    for plugin in plugins:
        if plugin.name in config.plugin_blacklist:
            plugins.remove(plugin)

    return plugins

@@ -357,16 +357,240 @@
 %22%22%0A%0A    
+plugins = set(plugin(config=config) for plugin in Plugin.subclasses())%0A%0A    for plugin in plugins:%0A        if plugin.name in config.plugin_blacklist:%0A            plugins.remove(plugin)%0A%0A    return plugins%0A%0A# import plugins%0A%0A
 cwd = pa
@@ -624,20 +624,16 @@
 ile__))%0A
-    
 files = 
@@ -649,20 +649,16 @@
 r(cwd)%0A%0A
-    
 for file
@@ -672,20 +672,16 @@
  files:%0A
-    
     name
@@ -713,20 +713,16 @@
 ename)%0A%0A
-    
     if n
@@ -750,20 +750,16 @@
         
-    
 continue
@@ -760,20 +760,16 @@
 ntinue%0A%0A
-    
     if e
@@ -789,19 +789,24 @@
         
-   
+module =
  importl
@@ -853,97 +853,121 @@
 me)%0A
-%0A
     
-plugins = set(plugin() for plugin in Plugin.subclasses())%0A%0A    for plugin in p
+    for name, item in module.__dict__.items():%0A            if type(item) == type and issubclass(item, P
 lugin
-s
+)
 :%0A  
@@ -976,102 +976,134 @@
     
-if plugin.name in config.plugin_blacklist:%0A            plugins.remove(plugin)%0A%0A    return plugins
+        item.name = item.__name__%0A                if item.name.endswith('Plugin'):%0A                    item.name = item.name%5B:-6%5D
 %0A

Make sure plugins' .name property gets set