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