Skip to content
Permalink
Browse files
load only command plugins when using nikola help
  • Loading branch information
ralsina committed Aug 15, 2015
1 parent 7ac80d9 commit c4e7628f9ab15067ac2e1cc66cf8b5b4b1faf75f
Showing with 40 additions and 26 deletions.
  1. +15 −6 nikola/__main__.py
  2. +25 −20 nikola/nikola.py
@@ -313,7 +313,6 @@ def get_cmds(self):

def run(self, cmd_args):
"""Run Nikola."""
sub_cmds = self.get_cmds()
args = self.process_args(cmd_args)
args = [sys_decode(arg) for arg in args]

@@ -335,6 +334,14 @@ def run(self, cmd_args):
if arg not in ('--help', '-h'):
args.append(arg)

if args[0] == 'help':
self.nikola.init_plugins(commands_only=True)
else:
self.nikola.init_plugins()
import pdb; pdb.set_trace()

sub_cmds = self.get_cmds()

if any(arg in ("--version", '-V') for arg in args):
cmd_args = ['version']
args = ['version']
@@ -345,12 +352,14 @@ def run(self, cmd_args):
for c in sub_filtered:
d = levenshtein(c, args[0])
sugg[d].append(c)
best_sugg = sugg[min(sugg.keys())]
if len(best_sugg) == 1:
LOGGER.info('Did you mean "{}"?'.format(best_sugg[0]))
else:
LOGGER.info('Did you mean "{}" or "{}"?'.format('", "'.join(best_sugg[:-1]), best_sugg[-1]))
if sugg.keys():
best_sugg = sugg[min(sugg.keys())]
if len(best_sugg) == 1:
LOGGER.info('Did you mean "{}"?'.format(best_sugg[0]))
else:
LOGGER.info('Did you mean "{}" or "{}"?'.format('", "'.join(best_sugg[:-1]), best_sugg[-1]))
return 3

if sub_cmds[args[0]] is not Help and not isinstance(sub_cmds[args[0]], Command): # Is a doit command
if not self.nikola.configured:
LOGGER.error("This command needs to run inside an "
@@ -715,9 +715,9 @@ def __init__(self, **config):
self.bad_compilers.add(k)

self._set_global_context()
self._init_plugins()
self.init_plugins()

def _init_plugins(self):
def init_plugins(self, commands_only=False):
"""Load plugins as needed."""
self.plugin_manager = PluginManager(categories_filter={
"Command": Command,
@@ -752,24 +752,29 @@ def _init_plugins(self):
self.plugin_manager.locatePlugins()
bad_candidates = set([])
for p in self.plugin_manager._candidates:
# 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 comopiler extension {}', p[-1].name)
if commands_only:
if p[-1].details.has_option('Nikola', 'plugincategory'):
if p[-1].details.get('Nikola', 'PluginCategory') != 'Command':
bad_candidates.add(p)
else: # Not commands-only
# 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 comopiler extension {}', p[-1].name)
self.plugin_manager._candidates = list(set(self.plugin_manager._candidates) - bad_candidates)
self.plugin_manager.loadPlugins()

0 comments on commit c4e7628

Please sign in to comment.