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

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

Merged
merged 1 commit into from
Jul 22, 2023

Conversation

AdamWill
Copy link
Contributor

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

  • I’ve read the guidelines for contributing.
  • I updated AUTHORS.txt and CHANGES.txt (if the change is non-trivial) and documentation (if applicable).
  • I tested my changes.

Description

@AdamWill AdamWill force-pushed the python312-yapsy-templatepath branch 3 times, most recently from df82f33 to 9fcde54 Compare July 15, 2023 17:16
@AdamWill
Copy link
Contributor Author

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 AdamWill force-pushed the python312-yapsy-templatepath branch from 9fcde54 to 4ef79ac Compare July 15, 2023 17:34
@AdamWill
Copy link
Contributor Author

AdamWill commented Jul 15, 2023

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.

This is a much cleaner (I think) approach to the problem of
figuring out the plugin's template path (see getnikola#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.

Signed-off-by: Adam Williamson <[email protected]>
@AdamWill AdamWill force-pushed the python312-yapsy-templatepath branch from 4ef79ac to 394d729 Compare July 15, 2023 23:31
@AdamWill
Copy link
Contributor Author

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 Kwpolska merged commit 88b8c03 into getnikola:master Jul 22, 2023
@Kwpolska
Copy link
Member

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants