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