The Python project provides a way to generate info files. The Python distribution has a Makefile which creates a venv along with a Sphinx project to generate a texi
file. The makeinfo
program can then convert the texi
to info
.
These instructions generate the Python documentation in info
format. The environment used here can often be used to generate manuals for other applications that provide a Makefile.
In addition to Python3000, these instructions require GNU Make and Texinfo. These are packaged in most Linux distributions. Different distros may use different naming conventions. Refer to your distro's documentation for the corresponding package names. For Debian based distros:
# install make to utilize the Makefiles provided by the Python project
~/$ sudo apt-get install make
# install texinfo for the `makeinfo` command
~/$ sudo apt-get install texinfo
Package names are usually similar for non-Debian systems. For Windows users, I recommend WSL or creating a virtual machine.
Navigate to https://www.python.org/ftp/python/ and download the tarball for your Python version. It will look like:
https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tar.xz
You can use wget
to download the tarball and tar
to unpack it. The options x
and f
are for "extract file":
# download the tarball
~/$ wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tar.xz
# extract the tarball
~/$ tar xf Python-3.7.9.tar.xz
Sphinx requires more dependencies than are bundled with the basic pip
install. Fortunately, the Python project provides a Makefile
to create the necessary environment. See the Makefile
for precise details.
# Navigate to the Doc/ directory
~/$ cd Python-3.7.9/Doc
# "create a venv with necessary tools"
~/Python-3.7.9/Doc$ make venv
# activate the venv created by make
~/Python-3.7.9/Doc$ source venv/bin/activate
Now that the correct environment is set up, we can run Sphinx. This call creates a cache used during generation with the -d
option. The documentation files found in the current directory are converted by the texinfo
"builder" and output to build/texinfo
:
# -b: Use the textinfo builder
# -d: Create "doctree pickles" cache in doctrees/
# Use the current directory as source
# Output to build/texinfo
(venv) ~/Python-3.7.9/Doc$ sphinx-build -b texinfo -d build/doctrees . build/texinfo
Again, the Python maintainers have given us what we need (even if they haven't documented it well). The previous command created a texi
file along with another Makefile
. The Makefile calls makeinfo
.
# Navigate to the output directory
(venv) ~/Python-3.7.9/Doc$ cd build/texinfo
# Run the generated Makefile
(venv) ~/Python-3.7.9/Doc/build/texinfo$ make
# Hark, unto us an info file is born
(venv) ~/Python-3.7.9/Doc/build/texinfo$ ls
Makefile python-figures python.info python.texi
Like Indiana Jones, you behold the Holy Grail. Many have perished in this journey; you have prevailed. Take a moment to celebrate.
Note: The makeinfo
conversion yields errors for me. No matter, I say. The desired info
is obtained and I greedily drink from it.
Use C-u C-h i
to directly open python.info
.
To install the info file within the Emacs Help Directory node, first
check C-h v Info-default-directory-list
for where info files are stored. Put python.info
file there. There may be a file called dir
in that directory. The dir
file is generated by texinfo
and contains the node listing. If no dir
file exists, don't worry, that's what we're creating. Note that it's not recommended to edit dir
files manually1.
Run update-info-dir
in whichever directory you put python.info
. This will update (or create) dir
with python.info
.
For complete details about the texinfo
system, see https://www.gnu.org/software/texinfo/manual/texinfo/html_node/Installing-an-Info-File.html.
1Aside from human error, like mistyping a reference, issues may arise due to "malformed" dir
files.