This package builds the Python language documentation
https://docs.python.org/3.15/ as a Qt Help archive (.qch), so that it can
be read offline in Qt Assistant and in Qt Creator's help pane, and reached
from Qt Creator with F1.
Unlike the cppreference documentation, which has to be scraped off a wiki,
the Python documentation is written in reStructuredText and built with
Sphinx, which carries a Qt Help builder of its own. So the source here is
not a copy of the website: it is CPython's own Doc/ tree, which make source clones, and what this package adds is the part Sphinx does not do.
That part is not peculiar to Python. CMake is written up in Sphinx as well
and ships an official .qch of its own, and its build -- Utilities/Sphinx
in the CMake sources -- has had to work around the same shortcomings of the
same builder: a nonav theme that colors nothing, a namespace that cannot be
configured, identifiers that come out wrong. The approach taken here is
CMake's, and the stylesheet template is adapted from theirs; what is new is
the part that is Python's own, which is mostly the identifiers.
-
A stylesheet. Sphinx's
qthelpbuilder renders with itsnonavtheme, which drops the sidebar and the scripts -- which is what a help pane wants -- but also leaves outbasic.cssand emits apygments.csswith no token colors in it, so the pages arrive with no layout and no syntax highlighting.static-qthelp/qthelp.css.insupplies both, and is configured twice: with a light palette intooffline.cssandoffline-simple.css, and with a dark one intooffline-dark.css. Qt Assistant and Qt Creator serve the dark sheet in place of either of the other two when their own theme is dark. -
The identifiers. Qt Creator answers F1 against the
idof a<keyword>, and Sphinx derives those by reading the parenthesis off the end of each index entry as a qualified name. That works for the members of a class --prmonth() (calendar.TextCalendar method)givescalendar.TextCalendar.prmonth-- and for nothing else: a module-level function readsjoin() (in module os.path), which it cannot parse, soos.path.joinand 5000 more had no identifier at all, and the C API, whose entries readPyList_New (C function), was filed under a scope namedC. So the Python names are taken from the build's own record of what it documented, theC.is dropped, and every identifier is also given a keyword under its dotted name, so that the Index pane can be searched byos.path.joinas well as by thejoin() (in module os.path)the website's index uses. CMake patches the same hole, for the kinds of thing its own domain documents, inUtilities/Sphinx/create_identifiers.py. -
The names. Sphinx hardcodes the namespace to
org.sphinx.python.<ver>and the virtual folder todoc; both are rewritten, so that several versions can be registered at once and the virtual folder does not collide with every other Sphinx-built archive. CMake rewrites the namespace too, inUtilities/Sphinx/fixup_qthelp_names.cmake. -
The landing page. Sphinx roots the table of contents at
contents.html, the page listing every section of every manual; the page the website opens on,index.html, is in the archive but not in the contents at all, because nothing in the documentation links down to it. The tree is hung off that one instead, with the old root kept as its first entry.
make
That is make source, make venv, make doc_qthelp and make doc_qch in
order, and leaves the archive at output/python-3.15.qch. The first run
clones CPython and builds a virtualenv, and takes a few minutes; afterwards
only the steps whose inputs changed are repeated. The clone stays on the
commit it was made at, so that a rebuild needs no network and two builds of
a version are the same build; make update moves it to the tip of its
branch, and the make after that picks the new commits up.
The version built is 3.15 unless another is asked for. Any other lands beside it rather than replacing it -- the namespace carries the version, so Qt Creator can hold several at once -- which is what these two would do:
make # output/python-3.15.qch, the default
make PYTHON_VERSION=3.14 # output/python-3.14.qch, beside it
make install copies the archive to $(docdir)/qch. To read it, register
it with Qt Creator under Help > Documentation > Add, or open it directly:
assistant -register output/python-3.15.qch
git, python3 (3.12 or newer) and qhelpgenerator, which ships with Qt in
libexec. make venv installs Sphinx and the rest of what CPython's Doc/
asks for into venv/. If qhelpgenerator is not on the path:
make QHELPGENERATOR=~/Qt/6.12.0/macos/libexec/qhelpgenerator
GPL version 3 or later; see LICENSE.
static-qthelp/qthelp.css.in is adapted from CMake's
Utilities/Sphinx/static-qthelp/qthelp.css.in, which is BSD 3-Clause and
remains so for the parts taken from it; that license permits redistributing
them here under the GPL, and the file's header says as much.
Nothing in this package is Python's own documentation. What make builds
from is CPython's Doc/ tree, which make source clones and which carries
the PSF license of the clone it comes from.
CMake's Qt Help build, under Utilities/Sphinx in the CMake sources, which
solves the same problem for the same builder and is where most of what is
here comes from. Worth reading alongside this:
qthelp_css.cmakeandstatic-qthelp/qthelp.css.in-- the stylesheet template and the two palettes, whichcommands/qch_css.pyis a port of.conf.py.in-- how CMake links the stylesheet, which it can do from its ownconf.py. CPython's is not ours to edit, socommands/qch_html.pyadds the link to the built pages instead.fixup_qthelp_names.cmakeandcreate_identifiers.py-- the namespace and the identifiers, both of whichcommands/qch_project.pydoes.
cppreference-doc, which builds the C++ reference the same way for the same help viewers, and from which this package takes its layout and its license.