getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.6k stars 444 forks source link

Use callback to set plugin module path for template location #3702

Closed AdamWill closed 1 year ago

AdamWill commented 1 year ago

This is a much cleaner (I think) approach to the problem of figuring out the plugin's template path (see #3701). We use yaspy's ability to provide a callback when loading the plugins. The callback is passed a yaspy.PluginInfo instance, which conveniently contains a reference to the plugin object itself, and its filesystem path. So we can just add a method on our plugin class to set the filesystem path as an attribute, and have the callback function call that method.

Pull Request Checklist

Description

AdamWill commented 1 year ago

This worked first time (bar persnickety linters). That always makes me suspicious, but I think it's actually okay! I tested it in the 'real world' (on my actual blog, which uses the static_comments plugin, which is affected by the underlying problem here) and it works, and the test suite passes.

AdamWill commented 1 year ago

bumped the yapsy requirement to 1.12.0, which seems to be the first version with callback_after in it. we need to use callback_after not callback because plugin_info.plugin_object is set between the two.

AdamWill commented 1 year ago

Resolved. Note the log message assumes the plugin will always have self.name - I figured this is safe as other code seems to do the same, but if not, we can make that safer.

Kwpolska commented 1 year ago

Thanks for the fix!