Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

57.6. python3-sphinx-9.1.0

Documentation generator — the manual pages of LLVM, CMake, mpd and flashrom

Version 9.1.0, release 1
Shelf python-libs — General-purpose python3-* runtime libraries: text, templating, markup, parsing, config, CLI, system, files, crypto, imaging
Phase 30_foundation (Build Foundation), 59 of 127 in build order
Licence BSD-2-Clause AND BSD-3-Clause AND MIT AND Apache-2.0 AND (0BSD OR CC0-1.0)
Homepage https://www.sphinx-doc.org/
Build time 0.9 SBU
Installed size 55.3 MiB in 3034 files
Recipe ports/core/python-libs/python3-sphinx/kpkgbuild

About

Sphinx is the documentation generator of the Python world and of many C and C++ projects: it reads reStructuredText, or Markdown through MyST, and builds HTML, LaTeX, EPUB or manual pages from it. It installs sphinx-build, sphinx-quickstart, sphinx-apidoc and sphinx-autogen.

In KDOS it is a manual-page generator. llvm, clang, lldb, cmake, mpd, flashrom, btrfs-progs, ghc, notmuch, khal and others build their manual pages with Sphinx’s man builder, and a Sphinx recipe ships that builder’s output alone; see Manual pages.

The port is unusual in where it installs. Sphinx needs a closure of Python packages that are not ports (the default theme alabaster, Babel, the sphinxcontrib-* builders, myst-parser and sphinx-argparse, among others), and some it needs, such as requests and urllib3, are ports already, installed in site-packages by a later phase. Two packages owning one path is a conflict kpkg refuses (Who owns a file), so Sphinx and that whole closure go into a prefix of their own, /usr/lib/python3-sphinx, and the commands in /usr/bin are a small launcher that puts the prefix on PYTHONPATH. The closure is the recipe’s pypackages list, vendored as source distributions (see The three Python keys).

Why it is in KDOS

The comment above the 3 ports from python3-jinja2 to python3-sphinx in script/phases/30_foundation/packages.txt:

Every file under libplacebo's src/shaders/ is GENERATED from a jinja template at build time, and its vendored copy of jinja is an empty submodule in the release archive.

Sources

Dependencies

Depends on: python3, python3-setuptools, python3-pip, python3-flit-core, python3-hatchling, python3-hatch-vcs, python3-docutils, python3-jinja2, python3-markupsafe, python3-pygments, python3-packaging, python3-certifi, python3-yaml.

Required by (16): btrfs-progs, castxml, clang, cmake, extra-cmake-modules, flashrom, ghc, git-cola, khal, khard, lldb, llvm, mpd, notmuch, spyder, vdirsyncer.

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/30_foundation/phase.env && kpkg install python3-sphinx'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/python-libs/python3-sphinx.

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/python-libs/python3-sphinx
echo '7741722357dd75f8190766926071fed3bdc211c74dd2d7d4df5404da95930ddb  python3-sphinx-9.1.0.tar.gz' | sha256sum -c -
echo '0baa1f3d9e27d17c58bc820df928af985d54314f39e1093176915361e73b2708  python3-sphinx-vendor-9.1.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/python3-sphinx
SRC=$SRC_ROOT/python3-sphinx-9.1.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf python3-sphinx-9.1.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:

_home=/usr/lib/python3-sphinx

mkdir -p vendor
tar -xf $PORT_SRC/$name-vendor-$version.tar.xz --strip-components=1 -C vendor

pip3 install --no-deps --no-index --find-links=vendor --no-build-isolation \
	--ignore-installed --root=$PKG --prefix=$_home \
	alabaster babel imagesize requests charset-normalizer idna urllib3 \
	roman-numerals snowballstemmer sphinxcontrib-applehelp \
	sphinxcontrib-devhelp sphinxcontrib-htmlhelp sphinxcontrib-jsmath \
	sphinxcontrib-qthelp sphinxcontrib-serializinghtml \
	myst-parser markdown-it-py mdit-py-plugins mdurl sphinx-argparse .

install -d "$PKG/usr/bin"
cat > "$PKG/usr/bin/sphinx-build" <<'KDOS_SH'
#!/bin/sh
home=/usr/lib/python3-sphinx
site=$(python3 -c 'import sys, sysconfig; print(sysconfig.get_path("purelib", vars={"base": sys.argv[1]}))' "$home") || exit 1
PYTHONPATH=$site${PYTHONPATH:+:$PYTHONPATH}
export PYTHONPATH
"$home/bin/${0##*/}" "$@"
KDOS_SH
chmod 755 "$PKG/usr/bin/sphinx-build"
for _cmd in sphinx-quickstart sphinx-apidoc sphinx-autogen; do
	[ -x "$PKG$_home/bin/$_cmd" ] || { echo "python3-sphinx: no $_cmd entry point" >&2; exit 1; }
	ln -s sphinx-build "$PKG/usr/bin/$_cmd"
done

PYTHONPATH=$(python3 -c 'import sys, sysconfig; print(sysconfig.get_path("purelib", vars={"base": sys.argv[1]}))' "$PKG$_home") \
	python3 -m sphinx -b man -q -d "$SRC_ROOT/sphinx-doctrees" \
	-D extensions=sphinx.ext.autodoc,sphinx.ext.doctest,sphinx.ext.todo,sphinx.ext.autosummary,sphinx.ext.extlinks,sphinx.ext.viewcode,sphinx.ext.inheritance_diagram,sphinx.ext.coverage,sphinx.ext.graphviz \
	doc "$SRC_ROOT/sphinx-man"
install -Dm644 "$SRC_ROOT"/sphinx-man/*.1 -t "$PKG/usr/share/man/man1"

The switches, and why each is set:

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/python3-sphinx, 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 python3-sphinx-9.1.0-1.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/python3-sphinx, and runs the triggers its paths call for.

Contents

Installed programs: sphinx-apidoc, sphinx-autogen, sphinx-build, sphinx-quickstart.

Installed directories: /usr/lib/python3-sphinx, /usr/share/licenses/python3-sphinx.

Short descriptions

sphinx-apidoc Sphinx API doc generator tool
sphinx-autogen Generate autodoc stub pages
sphinx-build Sphinx documentation generator tool
sphinx-quickstart Sphinx documentation template generator

Notes

import sphinx from a plain python3 fails, because the interpreter does not search the private prefix. A build that probes for Sphinx as a Python module instead of running sphinx-build does not find it, and has to be pointed at the command. A program that imports Sphinx at run time has to add the prefix to its own path: spyder’s package writes a .pth file naming the prefix’s site-packages.

The launcher is one script, /usr/bin/sphinx-build, and the other three commands are links to it. It asks python3 for the purelib path of /usr/lib/python3-sphinx (its lib/python3.<minor>/site-packages), puts that path in front of PYTHONPATH, and runs the entry point of the name it was called by from /usr/lib/python3-sphinx/bin. The for loop stops the build when one of those entry points is missing, so no link can point at nothing.

The pages are built after the install, by the Sphinx just installed into $PKG, found through the same purelib computation the launcher makes, so the build runs the packaged copy at least once.