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

scoping / import issue with plugin #3620

Open
x1101 opened this issue May 2, 2022 · 0 comments
Open

scoping / import issue with plugin #3620

x1101 opened this issue May 2, 2022 · 0 comments
Labels

Comments

@x1101
Copy link
Contributor

x1101 commented May 2, 2022

Environment

Python Version: 3.9.0

Nikola Version: Nikola v8.2.2

Operating System: Windows 10 / Fedora 35

Description:

Within the last ~45 days, I've experienced an odd scoping / import issue with the rss_ogg plugin (disclaimer, I am the author of that plugin), how it imports/uses _encolsure from nikola.nikola vs the locally defined version of the same method, and how to correct the issue in the plugin.

The plugin has fairly standard nikola imports

from nikola import utils
from nikola.nikola import _enclosure
from nikola.plugin_categories import 

and, later, defines its own version of _enclosure as such (which, I admit, is likely at least part of this error).

    def _enclosure(self, post, lang):
        """Add an enclosure to RSS."""
        enclosure = post.meta('ogg_enclosure', lang)
        if enclosure:
            try:
                length = int(post.meta('ogg_enclosure_length', lang) or 0)
            except KeyError:
                length = 0
            except ValueError:
                utils.LOGGER.warn("Invalid enclosure length for post {0}".format(post.source_path))
                length = 0
            url = enclosure
            mime = mimetypes.guess_type(url)[0]
            return url, length, mime

further on, it defines its task like this

task = {
                'basename': 'generate_rss_ogg',
                'name': os.path.normpath(output_name),
                'file_dep': deps,
                'targets': [output_name],
                'actions': [(utils.generic_rss_renderer,
                            (lang, kw["blog_title"](lang), kw["site_url"],
                             kw["blog_description"](lang), posts, output_name,
                             kw["feed_teasers"], kw["feed_plain"], kw['feed_length'], feed_url,
                             _enclosure, kw["feed_links_append_query"]))],

                'task_dep': ['render_posts'],
                'clean': True,
                'uptodate': [utils.config_changed(kw, 'nikola.plugins.task.rss')] + deps_uptodate,
            }

This is using nikola.nikola._enclosure rather than self.enclosure to render the xml file (I've verified this because it uses the enclosure/media info defined for a non-ogg xml file). As a short term fix/test, I've removed the import of nikola.nikola._enclosure and updated the task to call self._enclosure, but it seems like at least one of those is redundant.

Is there some kind of new scoping change/issue? Does anyone have advice on how to correct this in a clean/coherent way that is going to be better long term?

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

Successfully merging a pull request may close this issue.

1 participant