[arch-commits] Commit in calibre/trunk (4 files)

Eli Schwartz eschwartz at archlinux.org
Mon Nov 25 01:33:39 UTC 2019


    Date: Monday, November 25, 2019 @ 01:33:38
  Author: eschwartz
Revision: 533159

upgpkg: calibre 4.4.0-1: upstream release + python3

The python3 port is pretty far along now, and I've tested out parallel installs
in calibre-git on the AUR for a while now. Let's get this better tested and
hopefully find more bugs while preparing for official python3 support. Since I
anticipate people will at a minimum want to be able to run plugins, this shares
common code in a -common package, and comes with a simple script to switch the
single set of conflicting files (the /usr/bin entry points) between the python2
and python3 versions. Users can install either or both.

Added:
  calibre/trunk/calibre-alternatives.sh
  calibre/trunk/calibre-common.install
  calibre/trunk/calibre.install
Modified:
  calibre/trunk/PKGBUILD

-------------------------+
 PKGBUILD                |  109 ++++++++++++++++++++++++++++++++++++++--------
 calibre-alternatives.sh |   62 ++++++++++++++++++++++++++
 calibre-common.install  |    9 +++
 calibre.install         |    7 ++
 4 files changed, 169 insertions(+), 18 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2019-11-25 01:33:36 UTC (rev 533158)
+++ PKGBUILD	2019-11-25 01:33:38 UTC (rev 533159)
@@ -6,9 +6,10 @@
 # Contributor: Andrea Fagiani <andfagiani _at_ gmail dot com>
 # Contributor: Larry Hajali <larryhaja at gmail.com>
 
-pkgname=calibre
-pkgver=4.3.0
-pkgrel=3
+pkgbase=calibre
+pkgname=('calibre' 'calibre-common' 'calibre-python3')
+pkgver=4.4.0
+pkgrel=1
 pkgdesc="Ebook management application"
 arch=('x86_64')
 url="https://calibre-ebook.com/"
@@ -16,22 +17,25 @@
 _py_deps=('apsw' 'beautifulsoup4' 'cssselect' 'css-parser' 'dateutil' 'dbus' 'dnspython'
           'feedparser' 'html2text' 'html5-parser' 'lxml' 'markdown' 'mechanize' 'msgpack'
           'netifaces' 'unrardll' 'pillow' 'psutil' 'pygments' 'pyqt5' 'pyqtwebengine' 'regex')
+_py3_deps=("${_py_deps[@]}" 'zeroconf')
 depends=('chmlib' 'hunspell' 'icu' 'jxrlib' 'libmtp' 'libusbx' 'libwmf' 'mathjax2' 'mtdev' 'optipng'
-         'podofo' "${_py_deps[@]/#/python2-}" 'qt5-svg' 'udisks2')
-makedepends=('qt5-x11extras' 'rapydscript-ng' 'sip' 'xdg-utils')
+         'podofo' 'qt5-svg' 'udisks2')
+makedepends=("${_py_deps[@]/#/python2-}" "${_py3_deps[@]/#/python-}" 'qt5-x11extras'
+             'rapydscript-ng' 'sip' 'xdg-utils')
 checkdepends=('xorg-server-xvfb')
-optdepends=('ipython2: to use calibre-debug'
-            'poppler: required for converting pdf to html')
 source=("https://download.calibre-ebook.com/${pkgver}/calibre-${pkgver}.tar.xz"
-        "https://calibre-ebook.com/signatures/${pkgname}-${pkgver}.tar.xz.sig")
-sha256sums=('cf19f19da993c496a045c49d89f9232dd5ab23034acad2d14cba0bfab8178420'
-            'SKIP')
-b2sums=('fd187d1b68ac60c26c11094b0d19123f24ac93cde1e9939b71ecd4756c7a40ab55e4e36128763ed7f312df18a5152da418828ce84f4514a8747df8ccc3de2365'
-        'SKIP')
+        "https://calibre-ebook.com/signatures/${pkgbase}-${pkgver}.tar.xz.sig"
+        "calibre-alternatives.sh")
+sha256sums=('089ef0fedda62c0bf6f3fe87fbfe9c87e9537ff985bbd4cb376189326f6a77a2'
+            'SKIP'
+            '20dc4ff196423a7c7c8f644cb83fcfe07b4b5a64ba4addeb0750f94cd7aa9e8e')
+b2sums=('d6f6bfb98dd95012a7d145d7700a2818974b2d2e9f8faf1d98b931283305c92ec7e136c9569ef2074d748cc39819e53186ab250b8331d60253d23fddaa1f8a41'
+        'SKIP'
+        'c08d9587f9bb5c9b0f4be71bf5189515d2add7932ac5b504a11c8f5130fff129589a0cb58b7d4ffb172f454d993330b01ff153f59cbe4b626afec11f142ed631')
 validpgpkeys=('3CE1780F78DD88DF45194FD706BC317B515ACE7C') # Kovid Goyal (New longer key) <kovid at kovidgoyal.net>
 
 prepare(){
-    cd "${pkgname}-${pkgver}"
+    cd "${pkgbase}-${pkgver}"
 
     # Desktop integration (e.g. enforce arch defaults)
     # Use uppercase naming scheme, don't delete config files under fakeroot.
@@ -48,7 +52,7 @@
     cd resources
 
     # Remove unneeded files
-    rm ${pkgname}-portable.* mozilla-ca-certs.pem
+    rm ${pkgbase}-portable.* mozilla-ca-certs.pem
 
     # use system mathjax
     rm -r mathjax
@@ -55,24 +59,32 @@
 }
 
 build() {
-    cd "${pkgname}-${pkgver}"
+    cd "${pkgbase}-${pkgver}"
 
     LANG='en_US.UTF-8' python2 setup.py build
     LANG='en_US.UTF-8' python2 setup.py gui
     LANG='en_US.UTF-8' python2 setup.py mathjax --path-to-mathjax /usr/share/mathjax2 --system-mathjax
     LANG='en_US.UTF-8' python2 setup.py rapydscript
+
+    LANG='en_US.UTF-8' CALIBRE_PY3_PORT=1 python3 setup.py build
 }
 
 check() {
-    cd "${pkgname}-${pkgver}"
+    cd "${pkgbase}-${pkgver}"
 
     # without xvfb-run this fails with much "Control socket failed to recv(), resetting"
     # ERROR: test_websocket_perf (calibre.srv.tests.web_sockets.WebSocketTest)
+    # one or two tests are a bit flaky, but the python3 build seems to succeed more often
+    LANG='en_US.UTF-8' xvfb-run env CALIBRE_PY3_PORT=1 python3 setup.py test
     LANG='en_US.UTF-8' xvfb-run python2 setup.py test
 }
 
-package() {
-    cd "${pkgname}-${pkgver}"
+package_calibre-common() {
+    pkgdesc+=" (common files)"
+    optdepends=('poppler: required for converting pdf to html')
+    conflicts=("calibre<${pkgver}-${pkgrel}")
+    install=calibre-common.install
+    cd "${pkgbase}-${pkgver}"
 
     # If this directory doesn't exist, zsh completion won't install.
     install -d "${pkgdir}/usr/share/zsh/site-functions"
@@ -81,11 +93,39 @@
         --staging-root="${pkgdir}/usr" \
         --prefix=/usr
 
+    for bin in "${pkgdir}"/usr/bin/*; do
+        ln -sfT "/usr/lib/calibre/bin/${bin##*/}" "${bin}"
+    done
+
+    install -Dm755 "${srcdir}"/calibre-alternatives.sh "${pkgdir}"/usr/bin/calibre-alternatives
+
     cp -a man-pages/ "${pkgdir}/usr/share/man"
 
     # not needed at runtime
     rm -r "${pkgdir}"/usr/share/calibre/rapydscript/
 
+    #cleanup overlapping files
+    rm -r "${pkgdir}"/usr/lib/python2.7
+    rm -r "${pkgdir}"/usr/lib/calibre/calibre/plugins/
+    find "${pkgdir}" -type f -name '*.py[co]' -delete
+}
+
+package_calibre() {
+    pkgdesc+=" (python2 build)"
+    depends=('calibre-common' "${_py_deps[@]/#/python2-}")
+    optdepends+=('ipython2: to use calibre-debug')
+    install=calibre.install
+
+    cd "${pkgbase}-${pkgver}"
+
+    LANG='en_US.UTF-8' python2 setup.py install \
+        --staging-root="${pkgdir}/usr" \
+        --prefix=/usr \
+        --no-postinstall \
+        --bindir=/usr/lib/calibre/bin-py2 \
+        --staging-bindir="${pkgdir}/usr/lib/calibre/bin-py2" \
+        --staging-sharedir="${srcdir}"/temp
+
     # Compiling bytecode FS#33392
     # This is kind of ugly but removes traces of the build root.
     while read -rd '' _file; do
@@ -93,4 +133,37 @@
         python2 -m compileall -d "${_destdir}" "${_file}"
         python2 -O -m compileall -d "${_destdir}" "${_file}"
     done < <(find "${pkgdir}"/usr/lib/ -name '*.py' -print0)
+
+    # cleanup overlapping files
+    find "${pkgdir}"/usr/lib/calibre -name '*.py' -delete
+    rm -r "${pkgdir}"/usr/lib/calibre/calibre/plugins/3/
 }
+
+package_calibre-python3() {
+    pkgdesc+=" (experimental python3 port)"
+    depends=('calibre-common' "${_py3_deps[@]/#/python-}")
+    optdepends+=('ipython: to use calibre-debug')
+    install=calibre.install
+
+    cd "${pkgbase}-${pkgver}"
+
+    LANG='en_US.UTF-8' CALIBRE_PY3_PORT=1 python3 setup.py install \
+        --staging-root="${pkgdir}/usr" \
+        --prefix=/usr \
+        --no-postinstall \
+        --bindir=/usr/lib/calibre/bin-py3 \
+        --staging-bindir="${pkgdir}/usr/lib/calibre/bin-py3" \
+        --staging-sharedir="${srcdir}"/temp
+
+    # Compiling bytecode FS#33392
+    # This is kind of ugly but removes traces of the build root.
+    while read -rd '' _file; do
+        _destdir="$(dirname "${_file#${pkgdir}}")"
+        python3 -m compileall -d "${_destdir}" "${_file}"
+        python3 -O -m compileall -d "${_destdir}" "${_file}"
+    done < <(find "${pkgdir}"/usr/lib/ -name '*.py' -print0)
+
+    # cleanup overlapping files
+    find "${pkgdir}"/usr/lib/calibre -name '*.py' -delete
+    rm "${pkgdir}"/usr/lib/calibre/calibre/plugins/*.so
+}

Added: calibre-alternatives.sh
===================================================================
--- calibre-alternatives.sh	                        (rev 0)
+++ calibre-alternatives.sh	2019-11-25 01:33:38 UTC (rev 533159)
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+libdir=/usr/lib/calibre
+bindir=/usr/lib/calibre/bin
+
+die() {
+    echo "${1}" >&2
+    exit 1
+}
+
+usage() {
+    cat <<- __EOF__
+	usage: calibre-alternatives [help|get]
+	usage: calibre-alternatives set [2|3]
+
+	Set the default python interpreter for calibre, either python2 or python3.
+__EOF__
+}
+
+get_current() {
+    currentdir=$(readlink "${libdir}/bin")
+    echo "${currentdir##*-py}"
+}
+
+find_alternative() {
+    for i in 2 3; do
+        if [ -d "${libdir}/bin-py${i}" ]; then
+            echo "${i}"
+            return 0
+        fi
+    done
+    return 1
+}
+
+set_current() {
+    alt=${1}
+    if [ -z "${alt}" ]; then
+        [ -z "$(get_current)" ] || exit 0 # nothing to do
+        alt=$(find_alternative) || die "error: no alternatives exist"
+    fi
+
+    if ! [ $(id -u) = 0 ]; then
+        die "error: cannot set without being root"
+    fi
+
+    if [ -d "${libdir}/bin-py${alt}" ]; then
+        ln -snvf bin-py${alt} "${libdir}/bin"
+    else
+        die "alternative '${alt}' does not exist"
+    fi
+}
+
+case ${1} in
+    help)
+        usage;;
+    ''|get)
+        get_current;;
+    set)
+        shift; set_current "${1}";;
+    *)
+        die "invalid option: '${1}'"
+esac


Property changes on: calibre/trunk/calibre-alternatives.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: calibre-common.install
===================================================================
--- calibre-common.install	                        (rev 0)
+++ calibre-common.install	2019-11-25 01:33:38 UTC (rev 533159)
@@ -0,0 +1,9 @@
+post_install() {
+    echo '=> calibre and calibre-python3 are now co-installable'
+    echo '=> use `calibre-alternatives set [2|3]` to switch between them'
+}
+
+post_remove() {
+    rm -f /usr/lib/calibre/bin
+    rmdir /usr/lib/calibre/
+}

Added: calibre.install
===================================================================
--- calibre.install	                        (rev 0)
+++ calibre.install	2019-11-25 01:33:38 UTC (rev 533159)
@@ -0,0 +1,7 @@
+post_install() {
+    calibre-alternatives set
+}
+
+post_upgrade() {
+    calibre-alternatives set
+}



More information about the arch-commits mailing list