Repository: getnikola/nikola

Issue:
If plugins are not loaded because of config, plugin -r will not remove them
Quoting @punchagan: 

I think another issue is with magic being done here.

For instance, installing and uninstalling wiki plugin doesn't work on my site, because the compiler isn't being used.

Adding

self.site.plugin_manager.locatePlugins()
self.site.plugin_manager.loadPlugins()
before calling self.site.plugin_manager.getAllPlugins in plugin.py fixes it. But, may not be the best way to do it.



Discussion:

Resolving patch:
diff --git a/nikola/__main__.py b/nikola/__main__.py
--- a/nikola/__main__.py
+++ b/nikola/__main__.py
@@ -332,6 +332,8 @@ def run(self, cmd_args):
 
         if args[0] == 'help':
             self.nikola.init_plugins(commands_only=True)
+        elif args[0] == 'plugin':
+            self.nikola.init_plugins(load_all=True)
         else:
             self.nikola.init_plugins()
 
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -867,7 +867,7 @@ def __init__(self, **config):
             self.state._set_site(self)
             self.cache._set_site(self)
 
-    def init_plugins(self, commands_only=False):
+    def init_plugins(self, commands_only=False, load_all=False):
         """Load plugins as needed."""
         self.plugin_manager = PluginManager(categories_filter={
             "Command": Command,
@@ -901,34 +901,35 @@ def init_plugins(self, commands_only=False):
         self.plugin_manager.getPluginLocator().setPluginPlaces(self._plugin_places)
         self.plugin_manager.locatePlugins()
         bad_candidates = set([])
-        for p in self.plugin_manager._candidates:
-            if commands_only:
-                if p[-1].details.has_option('Nikola', 'plugincategory'):
-                    # FIXME TemplateSystem should not be needed
-                    if p[-1].details.get('Nikola', 'PluginCategory') not in {'Command', 'Template'}:
+        if not load_all:
+            for p in self.plugin_manager._candidates:
+                if commands_only:
+                    if p[-1].details.has_option('Nikola', 'plugincategory'):
+                        # FIXME TemplateSystem should not be needed
+                        if p[-1].details.get('Nikola', 'PluginCategory') not in {'Command', 'Template'}:
+                            bad_candidates.add(p)
+                    else:
                         bad_candidates.add(p)
-                else:
-                    bad_candidates.add(p)
-            elif self.configured:  # Not commands-only, and configured
-                # Remove compilers we don't use
-                if p[-1].name in self.bad_compilers:
-                    bad_candidates.add(p)
-                    self.disabled_compilers[p[-1].name] = p
-                    utils.LOGGER.debug('Not loading unneeded compiler {}', p[-1].name)
-                if p[-1].name not in self.config['COMPILERS'] and \
-                        p[-1].details.has_option('Nikola', 'plugincategory') and p[-1].details.get('Nikola', 'PluginCategory') == 'Compiler':
-                    bad_candidates.add(p)
-                    self.disabled_compilers[p[-1].name] = p
-                    utils.LOGGER.debug('Not loading unneeded compiler {}', p[-1].name)
-                # Remove blacklisted plugins
-                if p[-1].name in self.config['DISABLED_PLUGINS']:
-                    bad_candidates.add(p)
-                    utils.LOGGER.debug('Not loading disabled plugin {}', p[-1].name)
-                # Remove compiler extensions we don't need
-                if p[-1].details.has_option('Nikola', 'compiler') and p[-1].details.get('Nikola', 'compiler') in self.disabled_compilers:
-                    bad_candidates.add(p)
-                    utils.LOGGER.debug('Not loading compiler extension {}', p[-1].name)
-        self.plugin_manager._candidates = list(set(self.plugin_manager._candidates) - bad_candidates)
+                elif self.configured:  # Not commands-only, and configured
+                    # Remove compilers we don't use
+                    if p[-1].name in self.bad_compilers:
+                        bad_candidates.add(p)
+                        self.disabled_compilers[p[-1].name] = p
+                        utils.LOGGER.debug('Not loading unneeded compiler {}', p[-1].name)
+                    if p[-1].name not in self.config['COMPILERS'] and \
+                            p[-1].details.has_option('Nikola', 'plugincategory') and p[-1].details.get('Nikola', 'PluginCategory') == 'Compiler':
+                        bad_candidates.add(p)
+                        self.disabled_compilers[p[-1].name] = p
+                        utils.LOGGER.debug('Not loading unneeded compiler {}', p[-1].name)
+                    # Remove blacklisted plugins
+                    if p[-1].name in self.config['DISABLED_PLUGINS']:
+                        bad_candidates.add(p)
+                        utils.LOGGER.debug('Not loading disabled plugin {}', p[-1].name)
+                    # Remove compiler extensions we don't need
+                    if p[-1].details.has_option('Nikola', 'compiler') and p[-1].details.get('Nikola', 'compiler') in self.disabled_compilers:
+                        bad_candidates.add(p)
+                        utils.LOGGER.debug('Not loading compiler extension {}', p[-1].name)
+            self.plugin_manager._candidates = list(set(self.plugin_manager._candidates) - bad_candidates)
         self.plugin_manager.loadPlugins()
 
         self._activate_plugins_of_category("SignalHandler")


Test patch: