1#
2# Makefile for Python documentation
3# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4#
5
6# You can set these variables from the command line.
7PYTHON       = python3
8VENVDIR      = ./venv
9SPHINXBUILD  = PATH=$(VENVDIR)/bin:$$PATH sphinx-build
10BLURB        = PATH=$(VENVDIR)/bin:$$PATH blurb
11PAPER        =
12SOURCES      =
13DISTVERSION  = $(shell $(PYTHON) tools/extensions/patchlevel.py)
14SPHINXERRORHANDLING = -W
15
16# 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)) \
21                $(SPHINXOPTS) $(SPHINXERRORHANDLING) . build/$(BUILDER) $(SOURCES)
22
23.PHONY: help build html htmlhelp latex text texinfo changes linkcheck \
24	suspicious coverage doctest pydoc-topics htmlview clean dist check serve \
25	autobuild-dev autobuild-stable venv
26
27help:
28	@echo "Please use \`make <target>' where <target> is one of"
29	@echo "  clean      to remove build files"
30	@echo "  venv       to create a venv with necessary tools"
31	@echo "  html       to make standalone HTML files"
32	@echo "  htmlview   to open the index page built by the html target in your browser"
33	@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"
36	@echo "  texinfo    to make Texinfo file"
37	@echo "  epub       to make EPUB files"
38	@echo "  changes    to make an overview over all changed/added/deprecated items"
39	@echo "  linkcheck  to check all external links for integrity"
40	@echo "  coverage   to check documentation coverage for library and C API"
41	@echo "  doctest    to run doctests in the documentation"
42	@echo "  pydoc-topics  to regenerate the pydoc topics file"
43	@echo "  dist       to create a \"dist\" directory with archived docs for download"
44	@echo "  suspicious to check for suspicious markup in output text"
45	@echo "  check      to run a check for frequent markup errors"
46	@echo "  serve      to serve the documentation on the localhost (8000)"
47
48build:
49	-mkdir -p build
50# Look first for a Misc/NEWS file (building from a source release tarball
51# or old repo) and use that, otherwise look for a Misc/NEWS.d directory
52# (building from a newer repo) and use blurb to generate the NEWS file.
53	@if [ -f  ../Misc/NEWS ] ; then \
54		echo "Using existing Misc/NEWS file"; \
55		cp ../Misc/NEWS build/NEWS; \
56	elif $(BLURB) help >/dev/null 2>&1 && $(SPHINXBUILD) --version >/dev/null 2>&1; then \
57		if [ -d ../Misc/NEWS.d ]; then \
58			echo "Building NEWS from Misc/NEWS.d with blurb"; \
59			$(BLURB) merge -f build/NEWS; \
60		else \
61			echo "Neither Misc/NEWS.d nor Misc/NEWS found; cannot build docs"; \
62			exit 1; \
63		fi \
64	else \
65		echo ""; \
66		echo "Missing the required blurb or sphinx-build tools."; \
67		echo "Please run 'make venv' to install local copies."; \
68		echo ""; \
69		exit 1; \
70	fi
71	$(SPHINXBUILD) $(ALLSPHINXOPTS)
72	@echo
73
74html: BUILDER = html
75html: build
76	@echo "Build finished. The HTML pages are in build/html."
77
78htmlhelp: BUILDER = htmlhelp
79htmlhelp: build
80	@echo "Build finished; now you can run HTML Help Workshop with the" \
81	      "build/htmlhelp/pydoc.hhp project file."
82
83latex: BUILDER = latex
84latex: build
85	@echo "Build finished; the LaTeX files are in build/latex."
86	@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
87	      "run these through (pdf)latex."
88
89text: BUILDER = text
90text: build
91	@echo "Build finished; the text files are in build/text."
92
93texinfo: BUILDER = texinfo
94texinfo: build
95	@echo "Build finished; the python.texi file is in build/texinfo."
96	@echo "Run \`make info' in that directory to run it through makeinfo."
97
98epub: BUILDER = epub
99epub: build
100	@echo "Build finished; the epub files are in build/epub."
101
102changes: BUILDER = changes
103changes: build
104	@echo "The overview file is in build/changes."
105
106linkcheck: BUILDER = linkcheck
107linkcheck:
108	@$(MAKE) build BUILDER=$(BUILDER) || { \
109	echo "Link check complete; look for any errors in the above output" \
110	     "or in build/$(BUILDER)/output.txt"; \
111	false; }
112
113suspicious: BUILDER = suspicious
114suspicious:
115	@$(MAKE) build BUILDER=$(BUILDER) || { \
116	echo "Suspicious check complete; look for any errors in the above output" \
117	     "or in build/$(BUILDER)/suspicious.csv.  If all issues are false" \
118	     "positives, append that file to tools/susp-ignored.csv."; \
119	false; }
120
121coverage: BUILDER = coverage
122coverage: build
123	@echo "Coverage finished; see c.txt and python.txt in build/coverage"
124
125doctest: BUILDER = doctest
126doctest:
127	@$(MAKE) build BUILDER=$(BUILDER) || { \
128	echo "Testing of doctests in the sources finished, look at the" \
129	     "results in build/doctest/output.txt"; \
130	false; }
131
132pydoc-topics: BUILDER = pydoc-topics
133pydoc-topics: build
134	@echo "Building finished; now run this:" \
135	      "cp build/pydoc-topics/topics.py ../Lib/pydoc_data/topics.py"
136
137htmlview: html
138	 $(PYTHON) -c "import webbrowser; webbrowser.open('build/html/index.html')"
139
140clean:
141	-rm -rf build/* $(VENVDIR)/*
142
143venv:
144	$(PYTHON) -m venv $(VENVDIR)
145	$(VENVDIR)/bin/python3 -m pip install -U pip setuptools
146	$(VENVDIR)/bin/python3 -m pip install -r requirements.txt
147	@echo "The venv has been created in the $(VENVDIR) directory"
148
149dist:
150	rm -rf dist
151	mkdir -p dist
152
153	# archive the HTML
154	make html
155	cp -pPR build/html dist/python-$(DISTVERSION)-docs-html
156	tar -C dist -cf dist/python-$(DISTVERSION)-docs-html.tar python-$(DISTVERSION)-docs-html
157	bzip2 -9 -k dist/python-$(DISTVERSION)-docs-html.tar
158	(cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-html.zip python-$(DISTVERSION)-docs-html)
159	rm -r dist/python-$(DISTVERSION)-docs-html
160	rm dist/python-$(DISTVERSION)-docs-html.tar
161
162	# archive the text build
163	make text
164	cp -pPR build/text dist/python-$(DISTVERSION)-docs-text
165	tar -C dist -cf dist/python-$(DISTVERSION)-docs-text.tar python-$(DISTVERSION)-docs-text
166	bzip2 -9 -k dist/python-$(DISTVERSION)-docs-text.tar
167	(cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-text.zip python-$(DISTVERSION)-docs-text)
168	rm -r dist/python-$(DISTVERSION)-docs-text
169	rm dist/python-$(DISTVERSION)-docs-text.tar
170
171	# archive the A4 latex
172	rm -rf build/latex
173	make latex PAPER=a4
174	-sed -i 's/makeindex/makeindex -q/' build/latex/Makefile
175	(cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2)
176	cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-a4.zip
177	cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2
178
179	# archive the letter latex
180	rm -rf build/latex
181	make latex PAPER=letter
182	-sed -i 's/makeindex/makeindex -q/' build/latex/Makefile
183	(cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2)
184	cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-letter.zip
185	cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-letter.tar.bz2
186
187	# copy the epub build
188	rm -rf build/epub
189	make epub
190	cp -pPR build/epub/Python.epub dist/python-$(DISTVERSION)-docs.epub
191
192	# archive the texinfo build
193	rm -rf build/texinfo
194	make texinfo
195	make info --directory=build/texinfo
196	cp -pPR build/texinfo dist/python-$(DISTVERSION)-docs-texinfo
197	tar -C dist -cf dist/python-$(DISTVERSION)-docs-texinfo.tar python-$(DISTVERSION)-docs-texinfo
198	bzip2 -9 -k dist/python-$(DISTVERSION)-docs-texinfo.tar
199	(cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-texinfo.zip python-$(DISTVERSION)-docs-texinfo)
200	rm -r dist/python-$(DISTVERSION)-docs-texinfo
201	rm dist/python-$(DISTVERSION)-docs-texinfo.tar
202
203check:
204	$(PYTHON) tools/rstlint.py -i tools -i $(VENVDIR) -i README.rst
205
206serve:
207	$(PYTHON) ../Tools/scripts/serve.py build/html
208
209# Targets for daily automated doc build
210# By default, Sphinx only rebuilds pages where the page content has changed.
211# This means it doesn't always pick up changes to preferred link targets, etc
212# To ensure such changes are picked up, we build the published docs with
213# `-E` (to ignore the cached environment) and `-a` (to ignore already existing
214# output files)
215
216# for development releases: always build
217autobuild-dev:
218	make dist SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1 -A switchers=1'
219	-make suspicious
220
221# for quick rebuilds (HTML only)
222autobuild-dev-html:
223	make html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1 -A switchers=1'
224
225# for stable releases: only build if not in pre-release stage (alpha, beta)
226# release candidate downloads are okay, since the stable tree can be in that stage
227autobuild-stable:
228	@case $(DISTVERSION) in *[ab]*) \
229		echo "Not building; $(DISTVERSION) is not a release version."; \
230		exit 1;; \
231	esac
232	@make autobuild-dev
233
234autobuild-stable-html:
235	@case $(DISTVERSION) in *[ab]*) \
236		echo "Not building; $(DISTVERSION) is not a release version."; \
237		exit 1;; \
238	esac
239	@make autobuild-dev-html
240