Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When there is more than one copy of a plugin, use the most local one
  • Loading branch information
ralsina committed Jun 4, 2016
1 parent 88f7071 commit 10067d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -11,6 +11,7 @@ Features
Bugfixes
--------

* Avoid conflicts caused by multiple copies of the same plugin (#2362)
* Fix handling of some wordpress dumps (Issue #2340)
* When using the plugin command, load ALL plugins (Issue #2359)
* Fix plugin removal for plugins that are a package (Issue #2356)
Expand Down
20 changes: 18 additions & 2 deletions nikola/nikola.py
Expand Up @@ -28,7 +28,6 @@

from __future__ import print_function, unicode_literals
import io
from collections import defaultdict
from copy import copy
from pkg_resources import resource_filename
import datetime
Expand Down Expand Up @@ -888,8 +887,8 @@ def init_plugins(self, commands_only=False, load_all=False):
if sys.version_info[0] == 3:
self._plugin_places = [
resource_filename('nikola', 'plugins'),
os.path.join(os.getcwd(), 'plugins'),
os.path.expanduser('~/.nikola/plugins'),
os.path.join(os.getcwd(), 'plugins'),
] + [path for path in extra_plugins_dirs if path]
else:
self._plugin_places = [
Expand Down Expand Up @@ -930,6 +929,23 @@ def init_plugins(self, commands_only=False, load_all=False):
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)

# Find repeated plugins and discard the less local copy
def plugin_position_in_places(plugin):
for i, place in enumerate(self._plugin_places):
if plugin[0].startswith(place):
return i

plugin_dict = defaultdict(list)
for data in self.plugin_manager._candidates:
plugin_dict[data[2].name].append(data)
self.plugin_manager._candidates = []
for name, plugins in plugin_dict.items():
if len(plugins) > 1:
# Sort by locality
plugins.sort(key=plugin_position_in_places)
self.plugin_manager._candidates.append(plugins[-1])

self.plugin_manager.loadPlugins()

self._activate_plugins_of_category("SignalHandler")
Expand Down

0 comments on commit 10067d3

Please sign in to comment.