How do you get Python documentation in Texinfo Info format?
Asked Answered
J

11

35

Since Python 2.6, it seems the documentation is in the new reStructuredText format, and it doesn't seem very easy to build a Texinfo Info file out of the box anymore.

I'm an Emacs addict and prefer my documentation installed in Info.

Does anyone have Python 2.6 or later docs in Texinfo format? How did you convert them? Or, is there a maintained build somewhere out there?

I know I can use w3m or haddoc to view the html docs - I really want them in Info.

I've played with Pandoc but after a few small experiments it doesn't seem to deal well with links between documents, and my larger experiment - running it across all docs cat'ed together to see what happens - is still chugging along two days since I started it!

Two good answers

Highlighting two answers below, because SO won't allow me to accept both answers:

Johnsonian answered 28/6, 2009 at 13:11 Comment(4)
"Not programming related" - I assume you're kidding. My question is specifically about practising programming in a particular environment.Johnsonian
Did your pandoc script ever finish?Templia
Hi seth - in a sense, it did because I killed it. Two days was about enough for me to decide that it wasn't a great option. My experiments with smaller files showed it wasn't perfect. I've just started working on a rst2info project - if you (or anyone) is able to help, I'm putting it here: repo.or.cz/w/rst2info.git - it will be a bit of an uphill battle because I haven't written reStructuredText or Texinfo in my life, and TBH I have no real interest in learning it (or docutils) now.Johnsonian
I've packaged up the Python docs as a texinfo page, and released a package on MELPA to make them easy to install. Let me know how it works for you.Leet
L
10

I've packaged up the Python docs as a texinfo file.

If you're using Emacs with MELPA, you can simply install this with M-x package-install python-info.

Leet answered 17/9, 2013 at 10:56 Comment(4)
Perfect, down to the "This file is deliberately empty" description ;-) Thanks Wilfred.Johnsonian
Suggestion: could this plug into the C-h S machinery? This would make it vastly more useful!Blamed
@Clément hm, not sure how easy it would be. Could you open a GitHub issue describing how you'd imagine it working?Leet
I got it working by doing: export INFOPATH=$HOME/.emacs.d/etc/info/python3:" in my .bashrc, then copying the python.info into that folder. Emacs will consolidate all such dirs into `Info-default-directories'. Note the trailing ':' in the environment variable to prevent having to specify the default directories. I also created a "dir" file in that directory that just pointed to the python submodule. Not sure if this last was necessary.Paver
C
24

Jon Waltman http://bitbucket.org/jonwaltman/sphinx-info has forked sphinx and written a texinfo builder, it can build the python documentation (I've yet done it). It seems that it will be merged soon into sphinx.

Here's the quick links for the downloads (temporary):

Steps to generate python doc in texinfo format:

Download the python source code

Download and install the sphinx-info package (in a virtualenv)

Enter in the Python/Doc directory from the python sources

Edit the Makefile, to the build target replace $(PYTHON) tools/sphinx-build.py with sphinx-build, then add this target to the makefile, pay attention, the space before echo is a TAB:

texinfo: BUILDER = texinfo
texinfo: build
    @echo
    @echo "Build finished. The Texinfo files are in _build/texinfo."
    @echo "Run \`make' in that directory to run these through makeinfo" \
          "(use \`make info' here to do that automatically)."

Edit the Python/Doc/conf.py adding:

texinfo_documents = [
    ('contents', 'python', 'Python Documentation', 'Georg Brandl',
     'Python', 'The Python Programming Language', 'Documentation tools',
     1),
]

Then run make texinfo and it should produce the texifile in the build/texinfo directory. To generate the info file run makeinfo python.texi

Chenee answered 17/10, 2010 at 8:48 Comment(4)
I've had this question open for over a year, thanks for answering it! I'd earlier spotted Jon's work (see my answer from Sep 9th) but I didn't realise he'd gotten so far. I just ran install-info python.info and now I have all the Python docs at my fingertips. Awesome!Johnsonian
Can you describe the steps to genererate the .texi and .info files? I'd like to have the Python 2.7 docs.Automatism
I've added some guidelines please tell me if you are in trouble with itChenee
Thanks, that works. I needed a "sudo ginstall-info --dir-file=/usr/local/info/dir --info-file=python.info"Automatism
L
10

I've packaged up the Python docs as a texinfo file.

If you're using Emacs with MELPA, you can simply install this with M-x package-install python-info.

Leet answered 17/9, 2013 at 10:56 Comment(4)
Perfect, down to the "This file is deliberately empty" description ;-) Thanks Wilfred.Johnsonian
Suggestion: could this plug into the C-h S machinery? This would make it vastly more useful!Blamed
@Clément hm, not sure how easy it would be. Could you open a GitHub issue describing how you'd imagine it working?Leet
I got it working by doing: export INFOPATH=$HOME/.emacs.d/etc/info/python3:" in my .bashrc, then copying the python.info into that folder. Emacs will consolidate all such dirs into `Info-default-directories'. Note the trailing ':' in the environment variable to prevent having to specify the default directories. I also created a "dir" file in that directory that just pointed to the python submodule. Not sure if this last was necessary.Paver
B
5

With no doubt it would be cool and challenging to generate the Python documentation on your particular Python version by yourself. Just follow EmacsWiki, or feel free to compile it locally (at Debian Jessy for Python3.4.2):

sudo apt-get install python3-sphinx
cd ~/Desktop
wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2rc1.tar.xz
tar -xf Python-3.4.2rc1.tar.xz
cd Python-3.4.2rc1/Doc/
sphinx-build -b texinfo -d build/doctrees . build/texinfo
# extra time to build
cd build/texinfo/
makeinfo python.texi
# extra time for convertation

I got this tree:

.                                                                                                                              
├── logging_flow.png                                                                                                           
├── Makefile                                                                                                                   
├── pathlib-inheritance.png                                                                                                    
├── python.info                                                                                                                
├── python.info-1                                                                                                              
├── python.info-10                                                                                                             
├── python.info-11                                                                                                             
├── python.info-12                                                                                                             
├── python.info-13                                                                                                             
├── python.info-14                                                                                                             
├── python.info-15                                                                                                             
├── python.info-16                                                                                                             
├── python.info-17                                                                                                             
├── python.info-18                                                                                                             
├── python.info-19                                                                                                             
├── python.info-2                                                                                                              
├── python.info-20                                                                                                             
├── python.info-21                                                                                                             
├── python.info-22                                                                                                             
├── python.info-23                                                                                                             
├── python.info-24                                                                                                             
├── python.info-25                                                                                                             
├── python.info-26                                                                                                             
├── python.info-27                                                                                                             
├── python.info-28                                                                                                             
├── python.info-29                                                                                                             
├── python.info-3                                                                                                              
├── python.info-30                                                                                                             
├── python.info-31                                                                                                             
├── python.info-32                                                                                                             
├── python.info-33                                                                                                             
├── python.info-34                                                                                                             
├── python.info-4                                                                                                              
├── python.info-5                                                                                                              
├── python.info-6                                                                                                              
├── python.info-7                                                                                                              
├── python.info-8                                                                                                              
├── python.info-9                                                                                                              
├── python.texi                                                                                                                
├── python-video-icon.png                                                                                                      
├── tulip_coro.png                                                                                                             
└── turtle-star.png

And now it is possible to review python documentation natively in Emacs by

C-u C-h i python-info RET

python-info is a filename (fourth in the tree above), and even to bookmark some arbitrary nodes for habitual and regular reviewing convenience.

Byroad answered 11/3, 2017 at 18:29 Comment(2)
This is great, thanks! It looks like they fixed it since the dark ages of 2009. Given the popularity of MELPA I think Wilfred's answer will be useful to more people, so I will leave that one ticked, but if I could accept two answers I would definitely accept this one. I'll edit the description so this answer gets more visibility.Johnsonian
This is great! I noticed that there is a Makefile generated after sphinx-build, we can also use that to generate .info file (make info) and install info (make install-info)Cavendish
J
3

For those following this question in the hope of an answer, I found another rst2texinfo implementation which you might like to try:

http://bitbucket.org/jonwaltman/rst2texinfo/src

Johnsonian answered 9/9, 2010 at 3:43 Comment(0)
L
2

Another "workaround" is to execute pydoc as suggested by Nikokrock directly in Emacs:

(defun pydoc (&optional arg)
  (interactive)
  (when (not (stringp arg))
    (setq arg (thing-at-point 'word)))

  (setq cmd (concat "pydoc " arg))
  (ad-activate-regexp "auto-compile-yes-or-no-p-always-yes")
  (shell-command cmd)
  (setq pydoc-buf (get-buffer "*Shell Command Output*"))
  (switch-to-buffer-other-window pydoc-buf)
  (python-mode)
  (ad-deactivate-regexp "auto-compile-yes-or-no-p-always-yes")
)
Lind answered 1/7, 2009 at 11:54 Comment(1)
Thanks wr. That's a top tip for using Python in Emacs in general, but doesn't answer the question.Johnsonian
M
2

Michael Ernst used to maintain Info formats of Python docs:

http://www.cs.washington.edu/homes/mernst/software/#python-info

You can try using his makefile and html2texi script to generate an updated version. Both are linked at the above URL. I'm not sure how well it works now (the last version was around 2001), but his script is well commented (grep for "python").

Media answered 3/7, 2009 at 21:55 Comment(0)
H
2

For Python 3.8.0 and later, pre-built Info files are available at https://www.python.org/ftp/python/doc and/or https://docs.python.org/3/archives/.

Heavenly answered 23/1, 2021 at 17:47 Comment(0)
S
1

Python docs are now generated using Sphynx framework. This framework does not have texinfo output format. Currently it has:

  1. HTML
  2. latex
  3. plain text

Maybe you can get what you want using the Latex output. With the text output you will lost the cross ref.

Personnaly I prefer using pydoc when I want textual output. With Vim I have a shorcut to call pydoc and open a window with the doc for the entity under my cursor...

Seignior answered 29/6, 2009 at 21:34 Comment(3)
Thanks Nikokrock. I know about Sphinx, the original question links to it. I've dug about and it doesn't seem trivial to convert LaTeX to Texinfo - Pandoc seems more promising. There seem to be a few people watching this question but yours is the only answer so far - I wonder if most Python-Emacs programmers just live without Info since 2.6?Johnsonian
p.s. Here's links to a package that I found: members.inode.at/wjenkner/pari-info/… - I could get this or Pandoc working, or write my own converter, but what I'm seeking is a way of avoiding that if possible, because it's a bit of a distraction from the code I actually want to write! :-)Johnsonian
The latest trunk version of sphinx (1.1pre) actually does have a texinfo builder.Qianaqibla
S
1

The Ubuntu distribution provides packages pythonX.Y-doc (which include the documentation in Info format) at least since 18.04 (bionic); in 19.04 X.Y stands for 2.7, 3.7 and 3.8. The package does not have many dependencies, I assume it is possible to install it in other distributions too.

Spoilsport answered 29/10, 2019 at 16:36 Comment(0)
B
1

Believe it or not, the Python project actually provides us a way to do this through various Makefiles. The files utilize the Python Sphinx project to generate a texi file which makeinfo can then convert to info, the format Emacs uses for documentation.

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.

1. Download the documentation

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

2. Run make venv in Python-X.Y.Z/Doc

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

3. Run sphinx-build

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

4. Use makeinfo to generate the info file

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.

5. Load python.info into Emacs...

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.

Battle answered 1/12, 2020 at 23:35 Comment(2)
Thanks @lorem ipsum! I think this answer is substantially the same (albeit with extra instructions) as Alioth's (linked in the question now because it's only possible to accept 1 answer) -- let me know if I'm missing something?Johnsonian
I'd say that's accurate :)Battle
B
0

Build from source, which Emacs info browser recognizes:

git clone https://github.com/python/cpython.git
cd cpython
./configure
make
cd Doc
make texinfo
cd build/texinfo
make install-info infodir=/usr/local/share/info
Bigelow answered 30/6, 2024 at 3:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.