blob: f06689f83d8763969c7c62be534fa00e591e9673 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001#
2# Makefile for Python documentation
3# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4#
5
6# You can set these variables from the command line.
Victor Stinner91b0e7d2017-02-15 23:36:08 +01007PYTHON = python3
Ned Deily590665c2017-09-07 17:17:53 -07008VENVDIR = ./venv
9SPHINXBUILD = PATH=$(VENVDIR)/bin:$$PATH sphinx-build
10BLURB = PATH=$(VENVDIR)/bin:$$PATH blurb
Christian Heimes2c181612007-12-17 20:04:13 +000011PAPER =
Christian Heimesfe337bf2008-03-23 21:54:12 +000012SOURCES =
Benjamin Peterson82c05a52014-12-10 11:04:17 -050013DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py)
Julien Palardf98c1622018-11-03 19:06:33 +010014SPHINXERRORHANDLING = -W
Georg Brandl116aa622007-08-15 14:28:22 +000015
Jean-François Bb5381f62019-09-09 23:52:03 +020016# Internal variables.
17PAPEROPT_a4 = -D latex_elements.papersize=a4paper
18PAPEROPT_letter = -D latex_elements.papersize=letterpaper
19
20ALLSPHINXOPTS = -b $(BUILDER) -d build/doctrees $(PAPEROPT_$(PAPER)) \
Julien Palardf98c1622018-11-03 19:06:33 +010021 $(SPHINXOPTS) $(SPHINXERRORHANDLING) . build/$(BUILDER) $(SOURCES)
Georg Brandl116aa622007-08-15 14:28:22 +000022
Éric Araujof446d7a2014-03-13 19:30:43 -040023.PHONY: help build html htmlhelp latex text changes linkcheck \
Georg Brandlfe427fe2010-03-13 11:02:07 +000024 suspicious coverage doctest pydoc-topics htmlview clean dist check serve \
Ned Deily122fc132017-11-27 17:07:32 -050025 autobuild-dev autobuild-stable venv
Georg Brandl116aa622007-08-15 14:28:22 +000026
27help:
28 @echo "Please use \`make <target>' where <target> is one of"
Georg Brandlfe427fe2010-03-13 11:02:07 +000029 @echo " clean to remove build files"
Brett Cannond5ea39d2014-12-05 15:17:31 -050030 @echo " venv to create a venv with necessary tools"
Georg Brandlfe427fe2010-03-13 11:02:07 +000031 @echo " html to make standalone HTML files"
Zachary Ware9393fff2014-04-29 09:24:40 -050032 @echo " htmlview to open the index page built by the html target in your browser"
Georg Brandlfe427fe2010-03-13 11:02:07 +000033 @echo " htmlhelp to make HTML files and a HTML help project"
34 @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
35 @echo " text to make plain text files"
Georg Brandl183fe812011-01-05 11:00:25 +000036 @echo " epub to make EPUB files"
Georg Brandlfe427fe2010-03-13 11:02:07 +000037 @echo " changes to make an overview over all changed/added/deprecated items"
38 @echo " linkcheck to check all external links for integrity"
39 @echo " coverage to check documentation coverage for library and C API"
40 @echo " doctest to run doctests in the documentation"
41 @echo " pydoc-topics to regenerate the pydoc topics file"
42 @echo " dist to create a \"dist\" directory with archived docs for download"
Benjamin Peterson28d88b42009-01-09 03:03:23 +000043 @echo " suspicious to check for suspicious markup in output text"
Georg Brandlfe427fe2010-03-13 11:02:07 +000044 @echo " check to run a check for frequent markup errors"
45 @echo " serve to serve the documentation on the localhost (8000)"
Georg Brandl116aa622007-08-15 14:28:22 +000046
Ned Deily122fc132017-11-27 17:07:32 -050047build:
Ned Deilyfcd97d42017-09-05 00:10:31 -070048 -mkdir -p build
49# Look first for a Misc/NEWS file (building from a source release tarball
50# or old repo) and use that, otherwise look for a Misc/NEWS.d directory
51# (building from a newer repo) and use blurb to generate the NEWS file.
52 @if [ -f ../Misc/NEWS ] ; then \
53 echo "Using existing Misc/NEWS file"; \
54 cp ../Misc/NEWS build/NEWS; \
Gregory P. Smith3918ad62019-05-07 17:03:50 -040055 elif $(BLURB) help >/dev/null 2>&1 && $(SPHINXBUILD) --version >/dev/null 2>&1; then \
56 if [ -d ../Misc/NEWS.d ]; then \
57 echo "Building NEWS from Misc/NEWS.d with blurb"; \
58 $(BLURB) merge -f build/NEWS; \
59 else \
60 echo "Neither Misc/NEWS.d nor Misc/NEWS found; cannot build docs"; \
61 exit 1; \
62 fi \
Ned Deilyfcd97d42017-09-05 00:10:31 -070063 else \
Gregory P. Smith3918ad62019-05-07 17:03:50 -040064 echo ""; \
65 echo "Missing the required blurb or sphinx-build tools."; \
66 echo "Please run 'make venv' to install local copies."; \
67 echo ""; \
Ned Deilyfcd97d42017-09-05 00:10:31 -070068 exit 1; \
69 fi
Georg Brandlf7b2f362014-02-16 09:46:36 +010070 $(SPHINXBUILD) $(ALLSPHINXOPTS)
Georg Brandl116aa622007-08-15 14:28:22 +000071 @echo
72
73html: BUILDER = html
74html: build
75 @echo "Build finished. The HTML pages are in build/html."
76
Georg Brandl116aa622007-08-15 14:28:22 +000077htmlhelp: BUILDER = htmlhelp
78htmlhelp: build
79 @echo "Build finished; now you can run HTML Help Workshop with the" \
Guido van Rossumda27fd22007-08-17 00:24:54 +000080 "build/htmlhelp/pydoc.hhp project file."
Georg Brandl116aa622007-08-15 14:28:22 +000081
Christian Heimesd8654cf2007-12-02 15:22:16 +000082latex: BUILDER = latex
83latex: build
84 @echo "Build finished; the LaTeX files are in build/latex."
Christian Heimes2c181612007-12-17 20:04:13 +000085 @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
86 "run these through (pdf)latex."
Christian Heimesd8654cf2007-12-02 15:22:16 +000087
Georg Brandl0c77a822008-06-10 16:37:50 +000088text: BUILDER = text
89text: build
90 @echo "Build finished; the text files are in build/text."
91
Georg Brandl183fe812011-01-05 11:00:25 +000092epub: BUILDER = epub
93epub: build
94 @echo "Build finished; the epub files are in build/epub."
95
Christian Heimes5b5e81c2007-12-31 16:14:33 +000096changes: BUILDER = changes
97changes: build
98 @echo "The overview file is in build/changes."
99
Christian Heimes292d3512008-02-03 16:51:08 +0000100linkcheck: BUILDER = linkcheck
Serhiy Storchaka17f5f812014-07-22 10:24:25 +0300101linkcheck:
102 @$(MAKE) build BUILDER=$(BUILDER) || { \
103 echo "Link check complete; look for any errors in the above output" \
104 "or in build/$(BUILDER)/output.txt"; \
105 false; }
Christian Heimes292d3512008-02-03 16:51:08 +0000106
Benjamin Peterson28d88b42009-01-09 03:03:23 +0000107suspicious: BUILDER = suspicious
Serhiy Storchaka17f5f812014-07-22 10:24:25 +0300108suspicious:
109 @$(MAKE) build BUILDER=$(BUILDER) || { \
110 echo "Suspicious check complete; look for any errors in the above output" \
111 "or in build/$(BUILDER)/suspicious.csv. If all issues are false" \
Georg Brandl61bd1dc2014-09-30 22:56:38 +0200112 "positives, append that file to tools/susp-ignored.csv."; \
Serhiy Storchaka17f5f812014-07-22 10:24:25 +0300113 false; }
Benjamin Peterson28d88b42009-01-09 03:03:23 +0000114
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000115coverage: BUILDER = coverage
116coverage: build
117 @echo "Coverage finished; see c.txt and python.txt in build/coverage"
118
Christian Heimesfe337bf2008-03-23 21:54:12 +0000119doctest: BUILDER = doctest
Serhiy Storchaka17f5f812014-07-22 10:24:25 +0300120doctest:
121 @$(MAKE) build BUILDER=$(BUILDER) || { \
122 echo "Testing of doctests in the sources finished, look at the" \
123 "results in build/doctest/output.txt"; \
124 false; }
Christian Heimesfe337bf2008-03-23 21:54:12 +0000125
Georg Brandl6b38daa2008-06-01 21:05:17 +0000126pydoc-topics: BUILDER = pydoc-topics
127pydoc-topics: build
Larry Hastingse8ff0ca2015-05-30 16:58:27 -0700128 @echo "Building finished; now run this:" \
129 "cp build/pydoc-topics/topics.py ../Lib/pydoc_data/topics.py"
Georg Brandl6b38daa2008-06-01 21:05:17 +0000130
Benjamin Peterson41181742008-07-02 20:22:54 +0000131htmlview: html
132 $(PYTHON) -c "import webbrowser; webbrowser.open('build/html/index.html')"
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000133
Georg Brandl116aa622007-08-15 14:28:22 +0000134clean:
Ned Deily590665c2017-09-07 17:17:53 -0700135 -rm -rf build/* $(VENVDIR)/*
Brett Cannond5ea39d2014-12-05 15:17:31 -0500136
137venv:
Ned Deily122fc132017-11-27 17:07:32 -0500138 $(PYTHON) -m venv $(VENVDIR)
Stéphane Wirtel0a52d732019-05-14 13:49:49 +0200139 $(VENVDIR)/bin/python3 -m pip install -U pip setuptools
Julien Palard7d23dbe2019-06-15 15:41:58 +0200140 $(VENVDIR)/bin/python3 -m pip install -U Sphinx==2.0.1 blurb python-docs-theme
Ned Deily122fc132017-11-27 17:07:32 -0500141 @echo "The venv has been created in the $(VENVDIR) directory"
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000142
143dist:
Georg Brandl38557f22010-08-03 12:36:57 +0000144 rm -rf dist
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000145 mkdir -p dist
146
147 # archive the HTML
148 make html
Benjamin Peterson92035012008-12-27 16:00:54 +0000149 cp -pPR build/html dist/python-$(DISTVERSION)-docs-html
150 tar -C dist -cf dist/python-$(DISTVERSION)-docs-html.tar python-$(DISTVERSION)-docs-html
151 bzip2 -9 -k dist/python-$(DISTVERSION)-docs-html.tar
152 (cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-html.zip python-$(DISTVERSION)-docs-html)
153 rm -r dist/python-$(DISTVERSION)-docs-html
154 rm dist/python-$(DISTVERSION)-docs-html.tar
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000155
156 # archive the text build
157 make text
Benjamin Peterson92035012008-12-27 16:00:54 +0000158 cp -pPR build/text dist/python-$(DISTVERSION)-docs-text
159 tar -C dist -cf dist/python-$(DISTVERSION)-docs-text.tar python-$(DISTVERSION)-docs-text
160 bzip2 -9 -k dist/python-$(DISTVERSION)-docs-text.tar
161 (cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-text.zip python-$(DISTVERSION)-docs-text)
162 rm -r dist/python-$(DISTVERSION)-docs-text
163 rm dist/python-$(DISTVERSION)-docs-text.tar
Georg Brandl5617db82009-04-27 16:28:57 +0000164
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000165 # archive the A4 latex
Georg Brandl38557f22010-08-03 12:36:57 +0000166 rm -rf build/latex
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000167 make latex PAPER=a4
Georg Brandl692b3f82010-07-11 08:33:16 +0000168 -sed -i 's/makeindex/makeindex -q/' build/latex/Makefile
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000169 (cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2)
Benjamin Peterson92035012008-12-27 16:00:54 +0000170 cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-a4.zip
171 cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000172
173 # archive the letter latex
Georg Brandl38557f22010-08-03 12:36:57 +0000174 rm -rf build/latex
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000175 make latex PAPER=letter
Georg Brandl692b3f82010-07-11 08:33:16 +0000176 -sed -i 's/makeindex/makeindex -q/' build/latex/Makefile
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000177 (cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2)
Benjamin Peterson92035012008-12-27 16:00:54 +0000178 cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-letter.zip
179 cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-letter.tar.bz2
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000180
Georg Brandl865bdbf2014-03-28 19:48:55 +0100181 # copy the epub build
Georg Brandl183fe812011-01-05 11:00:25 +0000182 rm -rf build/epub
183 make epub
Georg Brandl865bdbf2014-03-28 19:48:55 +0100184 cp -pPR build/epub/Python.epub dist/python-$(DISTVERSION)-docs.epub
Georg Brandl183fe812011-01-05 11:00:25 +0000185
Georg Brandl45f53372009-01-03 21:15:20 +0000186check:
Ned Deily590665c2017-09-07 17:17:53 -0700187 $(PYTHON) tools/rstlint.py -i tools -i $(VENVDIR) -i README.rst
R. David Murraye821cb62010-03-08 17:48:38 +0000188
189serve:
Stéphane Wirtel09a9f172019-03-18 11:47:55 +0100190 $(PYTHON) ../Tools/scripts/serve.py build/html
Georg Brandlfe427fe2010-03-13 11:02:07 +0000191
Georg Brandl49f47182010-03-13 13:42:16 +0000192# Targets for daily automated doc build
Nick Coghlan7a82f9c2017-06-02 23:30:57 +1000193# By default, Sphinx only rebuilds pages where the page content has changed.
194# This means it doesn't always pick up changes to preferred link targets, etc
195# To ensure such changes are picked up, we build the published docs with
196# `-E` (to ignore the cached environment) and `-a` (to ignore already existing
197# output files)
Georg Brandlfe427fe2010-03-13 11:02:07 +0000198
199# for development releases: always build
200autobuild-dev:
Juliendff9b5f2017-08-07 10:27:21 +0200201 make dist SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1 -A switchers=1'
Georg Brandl44d24292013-11-24 16:17:54 +0100202 -make suspicious
Georg Brandlfe427fe2010-03-13 11:02:07 +0000203
Georg Brandl01f47e82012-10-28 08:09:02 +0100204# for quick rebuilds (HTML only)
Georg Brandl4b9e75b2016-06-15 08:57:32 +0200205autobuild-dev-html:
Juliendff9b5f2017-08-07 10:27:21 +0200206 make html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1 -A switchers=1'
Georg Brandl01f47e82012-10-28 08:09:02 +0100207
Benjamin Petersonefd713b2014-09-24 20:22:24 -0400208# for stable releases: only build if not in pre-release stage (alpha, beta)
209# release candidate downloads are okay, since the stable tree can be in that stage
Georg Brandlfe427fe2010-03-13 11:02:07 +0000210autobuild-stable:
Benjamin Petersonefd713b2014-09-24 20:22:24 -0400211 @case $(DISTVERSION) in *[ab]*) \
Georg Brandl49f47182010-03-13 13:42:16 +0000212 echo "Not building; $(DISTVERSION) is not a release version."; \
213 exit 1;; \
Georg Brandlfe427fe2010-03-13 11:02:07 +0000214 esac
215 @make autobuild-dev
Georg Brandl01f47e82012-10-28 08:09:02 +0100216
Georg Brandl4b9e75b2016-06-15 08:57:32 +0200217autobuild-stable-html:
218 @case $(DISTVERSION) in *[ab]*) \
219 echo "Not building; $(DISTVERSION) is not a release version."; \
220 exit 1;; \
221 esac
222 @make autobuild-dev-html