PeterFeicht / cppreference-doc

C++ standard library reference
en.cppreference.com
GNU General Public License v3.0
576 stars 47 forks source link

Premailer 3.9 breaks generation of cssless files (make doc_qch) #24

Closed AstralShadow closed 2 years ago

AstralShadow commented 2 years ago

Premailer 3.9 added a constructor argument with default value False that causes premailer.premailer.ExternalFileLoadingError when doing "make doc_qch"

From their README.md:

allow_loading_external_files=False # Allow loading any non-HTTP external file URL

Enabling it at commands/preprocess_cssless.py:77 fixes this, but it starts throwing an "unexpected keyword argument" exception when run with premailer <3.9

PeterFeicht commented 2 years ago

The Python requirements file specifies premailer version 3.7, so that's the one that should be used.

AstralShadow commented 2 years ago

My bad, i'm new to python and didn't knew about requirements.txt

badshah400 commented 2 years ago

FWIW, since for openSUSE Tumbleweed we have already moved to premailer 3.10, we needed a patch to get cppreference packages building. Here is what I have committed to the openSUSE package build [1]. Just in case this helps anyone else.

Index: cppreference-doc-20220730/commands/preprocess_cssless.py
===================================================================
--- cppreference-doc-20220730.orig/commands/preprocess_cssless.py
+++ cppreference-doc-20220730/commands/preprocess_cssless.py
@@ -72,8 +72,16 @@ def preprocess_html_merge_css(root, src_

     with warnings.catch_warnings():
         warnings.simplefilter("ignore")
-        premailer = Premailer(root, base_url=src_path,
-                              disable_link_rewrites=True, remove_classes=True)
+        try:
+            # Premailer >= 3.9
+            premailer = Premailer(root, base_url=src_path,
+                                  disable_link_rewrites=True, remove_classes=True,
+                                  allow_loading_external_files=True)
+        except:
+            # Premailer < 3.9
+            premailer = Premailer(root, base_url=src_path,
+                                  disable_link_rewrites=True, remove_classes=True)
+
         root = premailer.transform().getroot()

     return output.getvalue()

[1] https://build.opensuse.org/package/show/openSUSE:Factory/cppreference-doc

AstralShadow commented 2 years ago

That's a nice patch, supports both old and new versions :)