Subject: [PATCH 4/4] gnu: calibre: Add wrap phase for qtwebengine.

From: Brendan Tildesley <[email-masked]>
Date: Sun, 16 Aug 2020 17:03:18 +1000

* gnu/packages/ebook.scm (calibre): [arguments]: Copy the wrap phase
from Anki to wrap QTWEBENGINEPROCESS_PATH. This fixes the 'Could not
find QtWebEngineProcess error' when opening a book with the
ebook-viewer.
---
 gnu/packages/ebook.scm | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/ebook.scm b/gnu/packages/ebook.scm
index a434f56bc1..31864a0786 100644
--- a/gnu/packages/ebook.scm
+++ b/gnu/packages/ebook.scm
@@ -165,7 +165,10 @@
        ("qtwebengine" ,qtwebengine)
        ("sqlite" ,sqlite)))
     (arguments
-     `(#:python ,python-2
+     `(#:modules ((guix build python-build-system)
+                  (guix build utils)
+                  (ice-9 match))
+       #:python ,python-2
        ;; Calibre is using setuptools by itself, but the setup.py is not
        ;; compatible with the shim wrapper (taken from pip) we are using.
        #:use-setuptools? #f
@@ -252,6 +255,35 @@
               "man-pages"
               (string-append (assoc-ref outputs "out") "/share/man"))
              #t))
+         ;; wrap phase copied from anki package.
+         (add-after 'install 'wrap
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let ((bin (string-append (assoc-ref outputs "out") "/bin"))
+                   ;; List of paths to the site-packages directories of Python
+                   ;; library inputs.
+                   (site-packages
+                    (map (lambda (pyinput)
+                           (string-append
+                            (cdr pyinput)
+                            "/lib/python2.7/site-packages"))
+                         (filter (match-lambda
+                                   ((label . _)
+                                    (string-prefix? "python2-" label)))
+                                 inputs)))
+                   (qtwebengineprocess
+                    (string-append (assoc-ref inputs "qtwebengine")
+                                   "/lib/qt5/libexec/QtWebEngineProcess")))
+               ;; The program fails to find the QtWebEngineProcess program, so
+               ;; we set QTWEBENGINEPROCESS_PATH to help it.  PYTHONPATH is
+               ;; wrapped to avoid declaring Python libraries as propagated
+               ;; inputs.
+               (for-each (lambda (program)
+                           (wrap-program program
+                             `("QTWEBENGINEPROCESS_PATH" =
+                               (,qtwebengineprocess))
+                             `("PYTHONPATH" = ,site-packages)))
+                         (find-files bin ".")))
+             #t))
          ;; The font TTF files are used in some miscellaneous tests, so we
          ;; unbundle them here to avoid patching the tests.
          (add-after 'install 'unbundle-font-liberation
-- 
2.28.0