diff --git a/0001-Handle-change-to-plugin-loading-in-recent-yapsy-3700.patch b/0001-Handle-change-to-plugin-loading-in-recent-yapsy-3700.patch new file mode 100644 index 0000000..ab6dff1 --- /dev/null +++ b/0001-Handle-change-to-plugin-loading-in-recent-yapsy-3700.patch @@ -0,0 +1,86 @@ +From 50420559fa375a35afde860fb32ab3fe7412f279 Mon Sep 17 00:00:00 2001 +From: Adam Williamson +Date: Fri, 14 Jul 2023 15:53:00 -0700 +Subject: [PATCH] Handle change to plugin loading in recent yapsy (#3700) + +https://github.com/tibonihoo/yapsy/pull/11 changes yapsy plugin +loading to not use the deprecated imp module any more. However, +as a side effect of that, it breaks this already-kinda-ugly +hack, and we have to make it even uglier! + +yapsy used to import the module like this: + +imp.load_module(plugin_module_name,plugin_file...) + +where `plugin_module_name` was the modified, "unique" name it +creates early in `loadPlugins`. Interestingly, when you import +a module like that, it gets added to `sys.modules` under *both* +the modified name and its 'real' name, viz: + +>>> import sys +>>> import imp +>>> imp.load_module("someothername", None, "/usr/lib/python3.12/site-packages/yapsy/__init__.py", ("py", "r", imp.PKG_DIRECTORY)) + +>>> sys.modules["someothername"] + +>>> sys.modules["yapsy"] + + +That's why this hack worked. However, now yapsy imports the +module using importlib, then adds it to `sys.modules` itself, +*only* under the modified "unique" name, not under its original +name. So sys.modules["unmodifiedpluginname"] is now a KeyError. + +I can't think of a less ugly fix than this, unfortunately. We +*could* try sending a patch for yapsy to add it under both the +modified and unmodified names, but that would be somewhat tricky +in yapsy's design, and I also suspect yapsy would consider it +to actually be unwanted behavior. + +Maybe what we really need is to send a patch for yapsy to just +provide an interface to find a plugin's filesystem path... + +Signed-off-by: Adam Williamson +--- + nikola/plugin_categories.py | 24 +++++++++++++++++++++++- + 1 file changed, 23 insertions(+), 1 deletion(-) + +diff --git a/nikola/plugin_categories.py b/nikola/plugin_categories.py +index b4c486a78..bee9fe784 100644 +--- a/nikola/plugin_categories.py ++++ b/nikola/plugin_categories.py +@@ -75,8 +75,30 @@ class BasePlugin(IPlugin): + def inject_templates(self): + """Inject 'templates/' (if exists) very early in the theme chain.""" + try: ++ modname = "" ++ possmodnames = ( ++ self.__class__.__module__, ++ # since https://github.com/tibonihoo/yapsy/pull/11 , ++ # yapsy only adds each imported plugin to sys.modules ++ # under its modified, "unique" name (see early in ++ # PluginManager.loadPlugins), so we recreate the ++ # modified name here to find it. we fudge the serial ++ # number here, assuming that if a plugin is loaded ++ # under the same name multiple times, the location ++ # will also be the same, so we can just use 0. ++ "yapsy_loaded_plugin_" + self.__class__.__module__ + "_0", ++ "yapsy_loaded_plugin_" + self.name + "_0", ++ ) ++ for possmodname in possmodnames: ++ if possmodname in sys.modules: ++ modname = possmodname ++ if not modname: ++ # well, we tried. we wind up here for the dummy ++ # plugins; honestly I'm not sure exactly why/how, ++ # but they don't have templates, so it's okay ++ return + # Sorry, found no other way to get this +- mod_path = sys.modules[self.__class__.__module__].__file__ ++ mod_path = sys.modules[modname].__file__ + mod_dir = os.path.dirname(mod_path) + tmpl_dir = os.path.join( + mod_dir, 'templates', self.site.template_system.name +-- +2.41.0 + diff --git a/0001-Handle-change-to-plugin-loading-in-recent-yapsy.patch b/0001-Handle-change-to-plugin-loading-in-recent-yapsy.patch deleted file mode 100644 index d8b91c3..0000000 --- a/0001-Handle-change-to-plugin-loading-in-recent-yapsy.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 3099bfe1bbd92a835212ff109a82b782124a5c10 Mon Sep 17 00:00:00 2001 -From: Adam Williamson -Date: Fri, 14 Jul 2023 15:53:00 -0700 -Subject: [PATCH] Handle change to plugin loading in recent yapsy - -https://github.com/tibonihoo/yapsy/pull/11 changes yapsy plugin -loading to not use the deprecated imp module any more. However, -as a side effect of that, it breaks this already-kinda-ugly -hack, and we have to make it even uglier! - -yapsy used to import the module like this: - -imp.load_module(plugin_module_name,plugin_file...) - -where `plugin_module_name` was the modified, "unique" name it -creates early in `loadPlugins`. Interestingly, when you import -a module like that, it gets added to `sys.modules` under *both* -the modified name and its 'real' name, viz: - ->>> import sys ->>> import imp ->>> imp.load_module("someothername", None, "/usr/lib/python3.12/site-packages/yapsy/__init__.py", ("py", "r", imp.PKG_DIRECTORY)) - ->>> sys.modules["someothername"] - ->>> sys.modules["yapsy"] - - -That's why this hack worked. However, now yapsy imports the -module using importlib, then adds it to `sys.modules` itself, -*only* under the modified "unique" name, not under its original -name. So sys.modules["unmodifiedpluginname"] is now a KeyError. - -I can't think of a less ugly fix than this, unfortunately. We -*could* try sending a patch for yapsy to add it under both the -modified and unmodified names, but that would be somewhat tricky -in yapsy's design, and I also suspect yapsy would consider it -to actually be unwanted behavior. - -Maybe what we really need is to send a patch for yapsy to just -provide an interface to find a plugin's filesystem path... - -Signed-off-by: Adam Williamson ---- - nikola/plugin_categories.py | 20 +++++++++++++++++++- - 1 file changed, 19 insertions(+), 1 deletion(-) - -diff --git a/nikola/plugin_categories.py b/nikola/plugin_categories.py -index b4c486a78..6b813ea0b 100644 ---- a/nikola/plugin_categories.py -+++ b/nikola/plugin_categories.py -@@ -76,7 +76,25 @@ class BasePlugin(IPlugin): - """Inject 'templates/' (if exists) very early in the theme chain.""" - try: - # Sorry, found no other way to get this -- mod_path = sys.modules[self.__class__.__module__].__file__ -+ try: -+ mod_path = sys.modules[self.__class__.__module__].__file__ -+ except KeyError: -+ # since https://github.com/tibonihoo/yapsy/pull/11 , -+ # yapsy only adds each imported plugin to sys.modules -+ # under its modified, "unique" name (see early in -+ # PluginManager.loadPlugins), so we recreate the -+ # modified name here to find it. we fudge the serial -+ # number here, assuming that if a plugin is loaded -+ # under the same name multiple times, the location -+ # will also be the same, so we can just use 0 -+ try: -+ pluginmodname = "yapsy_loaded_plugin_" + self.name + "_0" -+ mod_path = sys.modules[pluginmodname].__file__ -+ except KeyError: -+ # well, we tried. we wind up here for the dummy -+ # plugins; honestly I'm not sure exactly why/how, -+ # but they don't have templates, so it's okay -+ return - mod_dir = os.path.dirname(mod_path) - tmpl_dir = os.path.join( - mod_dir, 'templates', self.site.template_system.name --- -2.41.0 - diff --git a/python-nikola.spec b/python-nikola.spec index 19254de..80342bd 100644 --- a/python-nikola.spec +++ b/python-nikola.spec @@ -2,7 +2,7 @@ Name: python-%{pypi_name} Version: 8.2.4 -Release: 2%{?dist} +Release: 3%{?dist} Summary: A modular, fast, simple, static website and blog generator License: MIT and CC0 and BSD @@ -11,7 +11,7 @@ Source0: https://github.com/getnikola/nikola/archive/v%{version}/nikola-% # https://github.com/getnikola/nikola/issues/3700 # https://github.com/getnikola/nikola/pull/3701 # Fix to work with Python 3.12-compatible yapsy -Patch: 0001-Handle-change-to-plugin-loading-in-recent-yapsy.patch +Patch: 0001-Handle-change-to-plugin-loading-in-recent-yapsy-3700.patch BuildArch: noarch BuildRequires: python3-devel @@ -165,6 +165,9 @@ pytest %changelog +* Fri Jul 14 2023 Adam Williamson - 8.2.4-3 +- Improve the plugin template loading patch + * Fri Jul 14 2023 Python Maint - 8.2.4-2 - Rebuilt for Python 3.12