nikola icon indicating copy to clipboard operation
nikola copied to clipboard

scoping / import issue with plugin

Open x1101 opened this issue 2 years ago • 0 comments

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?

x1101 avatar May 02 '22 17:05 x1101