300.4. deluge-2.2.0
BitTorrent client with a daemon, a GTK 3 interface, a web UI and a console UI
The build-state snapshot was taken from 2.2.0-1; this recipe is 2.2.0-2, so the size, time and contents below describe the earlier build.
| Version | 2.2.0, release 2 |
| Shelf | transfer — File transfer, synchronisation, backup and BitTorrent |
| Phase | 44_apps (Applications), 391 of 422 in build order |
| Licence | GPL-3.0-or-later |
| Homepage | https://deluge-torrent.org/ |
| Build time | 1.0 SBU |
| Installed size | 13.0 MiB in 1855 files |
| Recipe | ports/core/transfer/deluge/kpkgbuild |
About
Deluge is a BitTorrent client split into a daemon, deluged, and the interfaces that drive it: the GTK 3 window deluge-gtk, the web interface deluge-web and the console deluge-console. It is written in Python on Twisted, and does its torrent work through the Python binding of libtorrent-rasterbar, which must be of the 2.0 series: the 2.1 binding lacks settings and names the daemon uses, and deluged stops at start. The port installs the daemon, the three interfaces, the deluge command that starts whichever interface is set as the default, and the menu entry for the GTK window.
Sources
deluge-2.2.0.tar.gz(4.1 MiB)
sha256f0fc64e052334ef294ca3951975dd926f129d62813f6c909bb523d914abe6537
upstream: https://files.pythonhosted.org/packages/source/d/deluge/deluge-2.2.0.tar.gz
archive copy: sources-4/transfer--deluge-2.2.0.tar.gzdeluge-vendor-2.2.0.tar.xz(7.6 MiB)
sha256e126657d75080ce560236bb690b4f5d4459dab5bb984c6b11adc23998edbcc33
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-4/transfer--deluge--e126657d7508--deluge-vendor-2.2.0.tar.xz
Dependencies
Depends on: python3, python3-pip, python3-setuptools, python3-wheel, python3-hatchling, python3-hatch-vcs, python3-setuptools-scm, python3-versioneer, python3-cython, python3-packaging, python3-attrs, python3-typing-extensions, python3-idna, python3-twisted, python3-zope-interface, python3-cryptography, python3-mako, python3-pyxdg, python3-distro, python3-pillow, python3-gobject, python3-cairo, libtorrent-rasterbar, gtk3, librsvg, xdg-utils, hicolor-icon-theme.
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
no-pkg_resources.patch— Replace pkg_resources with importlib.metadata in deluge and its pluginsThe python3-setuptools port installs no pkg_resources module, and deluge/ui/ui_entry.py, deluge/pluginmanagerbase.py and the common.py of every plugin under deluge/plugins/ import it at the top, so unpatched neither the deluge command, the plugin manager nor any plugin can be imported.
deluge/common.py loses its pkg_resources fallback for the version lookup. ui_entry.py reads the deluge.ui entry points through importlib.metadata. The plugin manager walks the plugin directories itself, reads each .egg directory, .egg-info or .dist-info it finds with Distribution.at(), and loads the plugin from its entry points; it reads no zipped .egg file, so a plugin installed as one into ~/.config/deluge/plugins is not found. Each plugin's common.py takes resource_filename from deluge.common, which has the same (package, path) arguments.
pyopenssl-26.patch— Rewritesgenerate_ssl_keys()indeluge/crypto_utils.py, which makes the daemon’s key and self-signed certificate on its first start, to use thecryptographypackage instead ofOpenSSL.crypto. The bundled pyOpenSSL has noX509Req, which the unpatched code builds a certificate request with, so the firstdelugedstart would stop with anAttributeError. The key is still 2048-bit RSA, the subjectCN=Deluge Daemonand the validity three years; the serial number is random instead of 0. The patch’s header says it is not yet submitted upstream.release-check-off-by-default.patch— Sets the core preferencenew_release_checktoFalse, so the daemon does not ask deluge-torrent.org for a newer release at every start. It can be turned back on in the preferences.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/44_apps/phase.env && kpkg install deluge'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/transfer/deluge.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/transfer/deluge
echo 'f0fc64e052334ef294ca3951975dd926f129d62813f6c909bb523d914abe6537 deluge-2.2.0.tar.gz' | sha256sum -c -
echo 'e126657d75080ce560236bb690b4f5d4459dab5bb984c6b11adc23998edbcc33 deluge-vendor-2.2.0.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/deluge
SRC=$SRC_ROOT/deluge-2.2.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf deluge-2.2.0.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers pyrequirements, pyruntime and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/no-pkg_resources.patch"
patch -p1 -i "$PORT_SRC/pyopenssl-26.patch"
patch -p1 -i "$PORT_SRC/release-check-off-by-default.patch"
mkdir -p vendor
tar -xf $PORT_SRC/$name-vendor-$version.tar.xz --strip-components=1 -C vendor
_back="$SRC_ROOT/backends"
pip3 install --no-deps --no-index --find-links=vendor --no-build-isolation \
--target "$_back" hatch-fancy-pypi-readme rjsmin
export PYTHONPATH="$_back${PYTHONPATH:+:$PYTHONPATH}"
pip3 install --no-deps --no-index --find-links=vendor --no-build-isolation \
--ignore-installed --root=$PKG --prefix=/usr \
pyopenssl service-identity pyasn1 pyasn1-modules rencode \
setproctitle .
_site=$(python3 -c 'import sys, sysconfig; print(sysconfig.get_path("platlib", vars={"platbase": sys.argv[1], "base": sys.argv[1]}))' "$PKG/usr")
find "$_site/deluge/i18n" -mindepth 1 -maxdepth 1 -type d ! -name 'en*' -exec rm -rf {} +
for _egg in "$_site"/deluge/plugins/*.egg; do
mv "$_egg" "$_egg.zip"
python3 -m zipfile -e "$_egg.zip" "$_egg"
rm "$_egg.zip"
done
install -d "$PKG/usr/share/applications"
cat > "$PKG/usr/share/applications/deluge.desktop" <<'DESKTOP'
[Desktop Entry]
Type=Application
Name=Deluge
GenericName=BitTorrent Client
Comment=Download and share files over BitTorrent
Exec=deluge-gtk %U
Icon=deluge
Terminal=false
StartupWMClass=deluge
Categories=Network;FileTransfer;P2P;GTK;
Keywords=bittorrent;torrent;magnet;download;p2p;deluge;
DESKTOP
chmod 644 "$PKG/usr/share/applications/deluge.desktop"
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/deluge, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf deluge-2.2.0-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/deluge, and runs the triggers its paths call for.
Contents
Installed programs: deluge, deluge-console, deluge-gtk, deluge-web, deluged.
Installed directories: /usr/lib/python3.14/site-packages/OpenSSL, /usr/lib/python3.14/site-packages/deluge, /usr/lib/python3.14/site-packages/deluge-2.2.0.dist-info, /usr/lib/python3.14/site-packages/pyasn1, /usr/lib/python3.14/site-packages/pyasn1-0.6.4.dist-info, /usr/lib/python3.14/site-packages/pyasn1_modules, /usr/lib/python3.14/site-packages/pyasn1_modules-0.4.2.dist-info, /usr/lib/python3.14/site-packages/pyopenssl-26.4.0.dist-info, /usr/lib/python3.14/site-packages/rencode, /usr/lib/python3.14/site-packages/rencode-1.0.9.dist-info, /usr/lib/python3.14/site-packages/service_identity, /usr/lib/python3.14/site-packages/service_identity-26.1.0.dist-info, /usr/lib/python3.14/site-packages/setproctitle, /usr/lib/python3.14/site-packages/setproctitle-1.3.7.dist-info, /usr/share/licenses/deluge.
Short descriptions
deluge |
A BitTorrent client |
deluge-console |
A BitTorrent client console interface |
deluge-gtk |
A BitTorrent client Gtk interface |
deluge-web |
A BitTorrent client web interface |
deluged |
A BitTorrent client daemon |
Notes
The vendor bundle.
vendoring = pythonwith an explicitpypackageslist: the libraries Twisted needs for TLS (pyOpenSSL, service-identity, pyasn1 and pyasn1-modules), and rencode and setproctitle. Everything else Deluge imports is a port independs, among them python3-twisted and what it requires. Those must not join the bundle: a module two packages carry is a path two packages own, which kpkg refuses. How the three Python keys narrow a bundle is in The three Python keys.Build backends stay out of the package.
hatch-fancy-pypi-readmeis a build plugin of service-identity, andrjsminis the minifierminify_web_js.pyuses to build the web interface’s minified scripts when no Closure compiler is installed. The firstpip3 installputs the two into$SRC_ROOT/backends, onPYTHONPATH, so they reach the build and never$PKG.Two optional imports are left out.
setup.pylistschardetandifaddras extras.ifaddris already in cura’s bundle, and a module two packages carry is a path two packages own, which kpkg refuses (see Who owns a file). Withoutchardet,decode_bytes()indeluge/common.pytries UTF-8 and then Latin-1, and the tracker-icon fetcher reads a tracker’s HTML page as UTF-8.The bundled plugins are unpacked. Deluge’s build makes each plugin a zipped
.eggfile. The loop after the install unpacks each into a directory of the same name, for two reasons. The plugin scan ofno-pkg_resources.patchreads.eggdirectories,.egg-infoand.dist-info, and never a zipped.egg, so a zipped plugin dropped into~/.config/deluge/pluginsis not found either. Andresource_filename()indeluge/common.pyhands a plugin’s interface files out of a zip as a temporary copy that is gone by the time the plugin opens it.English only. Every directory under
deluge/i18nexcept the English ones is removed.The menu entry is written by
build.sh.gtkui.pycallsset_prgname('deluge'), so the window’s app_id isdeluge, whichStartupWMClassnames. It claims no MIME type or URL scheme, so it is not offered as the handler for.torrentfiles or magnet links.The ExtJS library inside the web interface ships as upstream built it; see What is built from source.
runtime = python3-mako. The web interface,deluge-web, renders its pages with Mako (deluge/ui/web/common.py), a submodule the run-time needs record does not read. python3-mako is a build-only port, so without the word a prebuilt install would leave it out anddeluge-webwould stop at start; the GTK client does not import it.