Skip to content
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

Merged
merged 4 commits into from
Jun 4, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
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
21 changes: 19 additions & 2 deletions nikola/nikola.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from __future__ import print_function, unicode_literals
import io
from collections import defaultdict
from copy import copy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaks everything!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it. I'll take a look when I come back

El sáb., jun. 4, 2016 14:55, Chris Warrick notifications@github.com
escribió:

In nikola/nikola.py
#2364 (comment):

@@ -28,7 +28,6 @@

from future import print_function, unicode_literals
import io
-from collections import defaultdict

Breaks everything!


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/getnikola/nikola/pull/2364/files/e06dc84de7647df6afee8700b444f73fb0e2384e#r65805487,
or mute the thread
https://github.com/notifications/unsubscribe/AAAGKxY67v-zXJwitNSEQSPBzO4YPB4Cks5qIbwYgaJpZM4IuKiY
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it and I’m currently testing this. Will merge if all works okay (which it currently does)

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,24 @@ 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, the 1st element is the path to the .plugin file
for i, place in enumerate(self._plugin_places):
if plugin[0].startswith(place):
Copy link
Member

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

return i

plugin_dict = defaultdict(list)
for data in self.plugin_manager._candidates:
plugin_dict[data[2].name].append(data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why [2], what are the previous positions?

Copy link
Member Author

Choose a reason for hiding this comment

The 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
plugin"

On Sat, Jun 4, 2016 at 1:37 PM Chris Warrick notifications@github.com
wrote:

In nikola/nikola.py
#2364 (comment):

@@ -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)
    

why [2], what are the previous positions?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/getnikola/nikola/pull/2364/files/10067d382d48c9c171fc6cece55dff9c203e917f#r65804619,
or mute the thread
https://github.com/notifications/unsubscribe/AAAGK8IiUkS8LYFmTiPZDyQOWCqeA4Vdks5qIanPgaJpZM4IuKiY
.

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