chiark / gitweb /
pelican-theme, m.code, m.dot: make stuff finally work on Pelican 4.5.1+.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 2 Jan 2022 16:29:27 +0000 (17:29 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 2 Jan 2022 18:21:30 +0000 (19:21 +0100)
Since Pelican 4.5 moved to "namespace plugins", the way plugins are
loaded is different and thus the root plugins/ directory is not in PATH
anymore, leading to errors like

    No module named 'ansilexer'
    No module named 'latex2svg'

After spending a bit of time looking into how "namespace plugins" are, I
decided to stay with what they say "legacy plugins" because that doesn't
require me to move everything into a pelican.plugins namespace and thus
allows me to reuse the exact same file for plugins to other m.css tools
like the Python doc generator.

Version 4.5.0 had loading of namespaced plugins (the `m.` here) broken
completely, which is why the CI got pinned to 4.2. With 4.5.1 it started
working again and due to how the tests were executed the PATH issues
weren't hit either, leading me to a false sense of security that
everything works again on 4.5.1, while it wasn't. This fix is the final
piece to make everything work again. Sorry that it took over a year to
get in.

Co-authored-by: Lukas Pirl <git@lukas-pirl.de>
package/ci/circleci.yml
pelican-theme/test/test_page.py
plugins/m/code.py
plugins/m/dot.py
plugins/m/math.py

index eba0b03a1c3b78929ab6129c81088464b562675b..e260518893c35adbd0b204da6be5d92d9c3124c6 100644 (file)
@@ -48,8 +48,6 @@ commands:
     steps:
     - run:
         name: Install Python dependencies
-        # Everything broken with Pelican 4.5, stay on older version until
-        # that's  resolved: https://github.com/mosra/m.css/issues/178
         # Pyphen 0.10 has significantly different hyphenation results, staying
         # on an  older version until I can investigate
         # Matplotlib 3.4.1 has different output AGAIN, staying on something
@@ -58,7 +56,7 @@ commands:
         # Attrs 20.3 add some new properties that I need to ignore first, using
         # 19.3 instead
         command: |
-          pip install jinja2 pelican==4.2.0 Pyphen==0.9.5 Pillow coverage codecov qrcode matplotlib<< parameters.matplotlib-version >> << parameters.extra >>
+          pip install jinja2 pelican Pyphen==0.9.5 Pillow coverage codecov qrcode matplotlib<< parameters.matplotlib-version >> << parameters.extra >>
     - run:
         name: Fix unheard-of cursed issues
         # otherwise i get Error: unsupported locale setting
index 219c3d981fff8c66a5f7c91bd9e93241dfc618f9..0f6c3acd5100af74b441f675e2077a26eb56a9d2 100644 (file)
@@ -159,7 +159,9 @@ class HtmlEscape(PageTestCase):
         self.assertEqual(*self.actual_expected_contents('landing.html'))
         self.assertEqual(*self.actual_expected_contents('breadcrumb.html'))
 
-    @unittest.skipUnless(LooseVersion(pelican.__version__) > LooseVersion("4.2.0"),
+    # Not merged for 4.7 yet and no time from my side to push the PR through,
+    # so let's defer this to blow up at some point in the future.
+    @unittest.skipUnless(LooseVersion(pelican.__version__) > LooseVersion("5.0.0"),
                          "https://github.com/getpelican/pelican/pull/2260")
     def test_content(self):
         self.run_pelican({
index 10593178c2331842bfae2fed648f999e923ee160..0878440fb91177772f54ecc01b2c021d5aae85fa 100644 (file)
@@ -40,7 +40,29 @@ import logging
 
 logger = logging.getLogger(__name__)
 
-import ansilexer
+try:
+    import ansilexer
+except ImportError:
+    # The above worked well on Pelican 4.2 and before, and also works with
+    # other m.css tools like the Python doc generator. Pelican 4.5.0 changed to
+    # "namespace plugins" and broke packaged plugins completely, 4.5.1 was
+    # fixed to load namespaced plugins again, however the loading code is
+    # different from 4.2 and thus anything from the root plugins/ directory
+    # *isn't* in PATH anymore. Thus attempting to import those modules fails
+    # and as a DIRTY hack I have to add the path back.
+    #
+    # TODO: Pelican 4.5+ treats everything that isn't in the pelican.plugins
+    # namespace as "legacy plugins", which is unfortunate because then I
+    # wouldn't be able to easily share the plugin code with other m.css tools
+    # which don't (and shouldn't need to) care about Pelican at all. Allowing
+    # 3rd party plugins without enforcing implicit assumptions on them (the
+    # namespace, an unprefixed register() function...) would probably involve a
+    # complex discussion with Pelican maintainers which I don't have the energy
+    # for right now. Let's hope the "legacy plugins" codepath stays in for the
+    # foreseeable future.
+    import sys
+    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+    import ansilexer
 
 filters_pre = None
 filters_post = None
index 4a3a2324f2482f415cab922f7564b702e216494c..54d99a457922acb84fcac9b9f1c1dd1a8cf3154a 100644 (file)
@@ -30,7 +30,16 @@ from docutils.parsers import rst
 from docutils.parsers.rst import directives
 from docutils.parsers.rst.roles import set_classes
 
-import dot2svg
+try:
+    import dot2svg
+except ImportError:
+    # While the above was enough to make things work with Pelican 4.2 and
+    # before (and also works with other m.css tools like the Python doc
+    # generator), Pelican 4.5.1+ needs the below (4.5.0 didn't work with
+    # namespaced plugins at all). See the comment in m.code for further info.
+    import sys
+    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+    import dot2svg
 
 def _is_graph_figure(parent):
     # The parent has to be a figure, marked as m-figure
index 1dd7ae70ff3443e3e6d547814ac2d75b29ec2060..f2399d47a31ab847e245986f536a569b15777dee 100644 (file)
@@ -32,8 +32,18 @@ from docutils.parsers import rst
 from docutils.parsers.rst import directives
 from docutils.parsers.rst.roles import set_classes
 
-import latex2svg
-import latex2svgextra
+try:
+    import latex2svg
+    import latex2svgextra
+except ImportError:
+    # While the above was enough to make things work with Pelican 4.2 and
+    # before (and also works with other m.css tools like the Python doc
+    # generator), Pelican 4.5.1+ needs the below (4.5.0 didn't work with
+    # namespaced plugins at all). See the comment in m.code for further info.
+    import sys
+    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+    import latex2svg
+    import latex2svgextra
 
 default_settings = {
     'INPUT': '',