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
When there is more than one copy of a plugin, use the most local one (fix #2362) #2364
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -888,8 +888,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 = [ | ||
|
@@ -930,6 +930,27 @@ 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): | ||
# plugin here is a tuple: | ||
# (path to the .plugin file, path to plugin module w/o .py, plugin metadata) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are "path to the .plugin file, path to the module, metadata about the On Sat, Jun 4, 2016 at 1:37 PM Chris Warrick notifications@github.com
|
||
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) | ||
utils.LOGGER.debug("Plugin {} exists in multiple places, using {}".format( | ||
plugins[-1][2].name, plugins[-1][0])) | ||
self.plugin_manager._candidates.append(plugins[-1]) | ||
|
||
self.plugin_manager.loadPlugins() | ||
|
||
self._activate_plugins_of_category("SignalHandler") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use some explainer comments that tell future readers what
plugin
is here, it took me a while to parse all this