mosra / m.css

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

Plugins cannot be loaded with Pelican 4.5.0 #181

Closed shniubobo closed 2 years ago

shniubobo commented 4 years ago

With Pelican 4.5.0, the plugins cannot be loaded with PLUGINS += ['m.x'] (where x is the plugin's name). A workaround is to put plugins outside of the m directory and use PLUGINS += ['x'] instead.

This is to be fixed in later versions of Pelican.

Related issues: #178, https://github.com/getpelican/pelican/issues/2805

egberts commented 4 years ago

Yeah, I got the same. Did some debugging. Noticed that Pelican 4.5 cannot use namespace_plugins approach, so it resorts to load_legacy() approach.

egberts commented 4 years ago

I'm running Pelican 4.5.0 and am still experiencing load_legacy() not found issue.

$ python3.8 -c "import pelican;print(pelican.__version__)"
4.5.0

At 7a6686f4 (origin/master, origin/HEAD) Fix SUMMARY_END_SUFFIX variable name in changelog

I've done a git submodule checkout of m.css into the working area of a website such that this directory layout is:

+ egbert.net
|-- content
|-- output
|-- plugins
|-- m.css
   |
   +-- plugins
      +-- ansilexer.py
      +-- dot2svg.py
      +-- latex2svg.py
      +-- latex2svgextra.py
      +-- m
         +-- htmlsanity.py
         +-- metadata.py 
...

I used the following plugin settings:

PLUGIN_PATHS = [ './plugins', 'm.css/plugins' ]
PLUGINS = [
#          'i18n_subsites',
          'collate_content',
          'sitemap',
          'dateish',
          'tag_cloud',
          'm.alias',
          'm.htmlsanity',
          'm.images',
          'm.math',
          'just_table',
          'code_include',
]

And my console output for Pelican was:

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

Surely, I must be misreading the documentation or something, am I?

shniubobo commented 4 years ago

Surely, I must be misreading the documentation or something, am I?

From https://github.com/mosra/m.css/issues/181#issue-718676189:

This is to be fixed in later versions of Pelican.

egberts commented 4 years ago

I wonder if it would be made easier if the period in m.css is replaced with an underscore “_” symbol.

mosra commented 4 years ago

Nooo, that's ugly! :trollface:

In all seriousness, there's a proposed patch, so I think it's easier for everyone involved to just stay on 4.2 until this behavior is restored. Changing everything to an underscore means I need to change all docs, break compatibility with 4.2 (which would make a lot of existing users angry) and break also Python and Doxygen themes (because these use those plugins too).

egberts commented 4 years ago

Unfortunately, I’ve taken the proposed fix and tried a few variants of my own but it looks like legacy plugins are screwed until next Python subsubversion.

ikeingtonbear commented 3 years ago

I seem to be having a related issue, but not with m.[plugin] plugins, rather the plugins directly under the m.css/plugins directory. I'm trying to use the code plugin, but it's unable to load the ansilexer moulde.

Here is some of my debug output:

DEBUG: Pelican version: 4.5.3
DEBUG: Python version: 3.9.1
DEBUG: Adding current directory to system path
DEBUG: Finding namespace plugins
DEBUG: Loading plugin `m.htmlsanity`
DEBUG: Loading plugin `m.code`
ERROR: Cannot load plugin `m.code`
  | No module named 'ansilexer'
DEBUG: Loading plugin `m.components`
DEBUG: Loading plugin `m.images`
DEBUG: Registering plugin `m.htmlsanity`
DEBUG: Registering plugin `m.components`
DEBUG: Registering plugin `m.images`

Snippets from my pelicanconf.py file:

PLUGIN_PATHS = ['m.css/plugins']
PLUGINS = ['m.htmlsanity', 'm.code', 'm.components', 'm.images']

If this is unrelated please let me know and I'll submit a new issue.

benlawraus commented 2 years ago

Same problem on Pelican 4.7.

shniubobo commented 2 years ago

Same problem on Pelican 4.7.

I cannot reproduce the problem on either pelican 4.7.0 or 4.7.1 with the methods specified at https://github.com/getpelican/pelican/issues/2805 (the second one). Could you please specify how to reproduce it on pelican 4.7?

lpirl commented 2 years ago

@benlawraus: I can confirm the statement of @shniubobo that plugin loading generally works again (tested Pelican 4.7.0 and 4.7.1); e.g. with:

PLUGIN_PATHS.append('themes/m.css/plugins')
PLUGINS.append('m.htmlsanity')

But I also did experience the behavior that @ikeingtonbear mentioned. In my case the plugin m.dot could not be loaded (got No module named 'dot2svg'). So apparently putting themes/m.css/plugins in PLUGIN_PATHS does not suffice to have this path in the sys.path/PYTHONPATH. I don't know where this should be fixed (plugin, Pelican, …?) but putting themes/m.css/plugins in the sys.path worked for me as a workaround. In your Pelican configuration, this would look like:

…
import sys
…
PLUGIN_PATHS.append('themes/m.css/plugins')
…
PLUGINS.append('m.dot')
# maybe add a comment here:
sys.path.append('themes/m.css/plugins')
MinchinWeb commented 2 years ago

I was mucking around with my Pelican plugins and ran into this same issue (I think). I was able to solve it my moving the plugin from a "raw" file into the __init__.py file of a folder. So cname.py became cname/__init__.py. Your call on whether that is "beautiful" enough to implement :)

mosra commented 2 years ago

Okay, sorry everyone that it took half a century for me to finally act on this matter. The remaining issue with the paths should be hacked up fixed in 47c005b8523437ff28001c8c47a6360f985c2a28 (@lpirl thanks for providing a simple-enough idea for a fix). I'm now running on Pelican 4.7.1 locally and my excessive use of all plugins seems to work almost as good as it did back then with 4.2.

Now onto the remaining 100s of unresolved issues...