mosra / m.css

A no-nonsense, no-JavaScript CSS framework, site and documentation theme for content-oriented websites
https://mcss.mosra.cz
Other
406 stars 92 forks source link

Broken imports in plugins with Pelican 4.5 #178

Closed shniubobo closed 3 years ago

shniubobo commented 3 years ago

As of https://github.com/getpelican/pelican/commit/58edad6897931f21c7c2f4314cfab33c2b167680, import pelican.signals is no longer valid, and should be replaced with one of:

I found this issue when trying to use plugins/m/htmlsanity.py, and the plugin works fine after the following modification:

diff --git a/plugins/m/htmlsanity.py b/plugins/m/htmlsanity.py
index 37ce088..987c56c 100644
--- a/plugins/m/htmlsanity.py
+++ b/plugins/m/htmlsanity.py
@@ -730,7 +730,7 @@ def register_mcss(mcss_settings, jinja_environment, **kwargs):
 # Below is only Pelican-specific functionality. If Pelican is not found, these
 # do nothing.
 try:
-    import pelican.signals
+    from pelican import signals
     from pelican.readers import RstReader

     class PelicanSaneRstReader(RstReader):
@@ -800,5 +800,5 @@ def _pelican_add_reader(readers):
     readers.reader_classes['rst'] = PelicanSaneRstReader

 def register(): # for Pelican
-    pelican.signals.initialized.connect(_pelican_configure)
-    pelican.signals.readers_init.connect(_pelican_add_reader)
+    signals.initialized.connect(_pelican_configure)
+    signals.readers_init.connect(_pelican_add_reader)
mosra commented 3 years ago

Ohh, much thanks for investigating this issue :heart:

I am aware that everything got broken since Pelican 4.5 but didn't have any time to look into it yet. Is this really everything needed to make things work again? That would be awesome.

I had an impression that having plugins in a submodule stopped working also (as in, PLUGINS += ['m.htmlsanity'] no longer worked), but maybe that was a consequence of this import error.

shniubobo commented 3 years ago

At first I tried using the plugin as is instructed in https://mcss.mosra.cz/plugins/htmlsanity/, but pelican kept saying:

ERROR: Cannot load plugin `m.htmlsanity`
  | No module named 'm'

Later I moved htmlsanity.py outside of the m directory and tried PLUGINS += ['htmlsanity']. Although the plugin still did not work, the logging of pelican changed into:

ERROR: Cannot register plugin `htmlsanity`
  | name 'pelican' is not defined

So I guessed pelican was not correctly imported. After removing the try...except statements in htmlsanity.py, I got the following error:

ModuleNotFoundError: No module named 'pelican.signals'

After investigating the blame info of https://github.com/getpelican/pelican/blob/master/pelican/__init__.py, I found the very commit (https://github.com/getpelican/pelican/commit/58edad6897931f21c7c2f4314cfab33c2b167680) that introduced the issue.

With the aforementioned modification to htmlsanity.py, it can now work with PLUGINS += ['htmlsanity'], but still not with PLUGINS += ['m.htmlsanity']🙁

mosra commented 3 years ago

Okay, that's what I feared -- that everyone upgrading to Pelican 4.5 would need to change this in their settings :(

Do you have time to investigate why the submodule no longer works? If not, I'll check myself when I get to it.

shniubobo commented 3 years ago

I tried to but could not find the reason why m.htmlsanity is not working 🙁

When I type python -c "import m" inside the plugins folder, it exits with 0, so the module m is valid. But when I invoke pelican, it keeps saying:

ERROR: Cannot load plugin `m.htmlsanity`
  | No module named 'm'

Here are my settings:

PLUGINS = [
    'm.htmlsanity',
]
PLUGIN_PATHS = [
    'plugins',
]

And inside the plugins directory, I have a symlink m that points to the m.css/plugins/m directory.

shniubobo commented 3 years ago

In pelican's documents, it says that namespace plugins (such as m.htmlsanity) need to be installable. Maybe a setup.py could solve the issue? 🤔