|
| 1 | +# |
| 2 | +# Makefile for Python documentation |
| 3 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4 | +# |
| 5 | + |
| 6 | +# You can set these variables from the command line. |
| 7 | +PYTHON = python3 |
| 8 | +VENVDIR = ./venv |
| 9 | +SPHINXBUILD = PATH=$(VENVDIR)/bin:$$PATH sphinx-build |
| 10 | +BLURB = PATH=$(VENVDIR)/bin:$$PATH blurb |
| 11 | +PAPER = |
| 12 | +SOURCES = |
| 13 | +DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py) |
| 14 | +SPHINXERRORHANDLING = -W |
| 15 | + |
| 16 | +# Internal variables. |
| 17 | +PAPEROPT_a4 = -D latex_elements.papersize=a4paper |
| 18 | +PAPEROPT_letter = -D latex_elements.papersize=letterpaper |
| 19 | + |
| 20 | +ALLSPHINXOPTS = -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 | + |
| 27 | +help: |
| 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 | + |
| 48 | +build: |
| 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 | + |
| 74 | +html: BUILDER = html |
| 75 | +html: build |
| 76 | + @echo "Build finished. The HTML pages are in build/html." |
| 77 | + |
| 78 | +htmlhelp: BUILDER = htmlhelp |
| 79 | +htmlhelp: build |
| 80 | + @echo "Build finished; now you can run HTML Help Workshop with the" \ |
| 81 | + "build/htmlhelp/pydoc.hhp project file." |
| 82 | + |
| 83 | +latex: BUILDER = latex |
| 84 | +latex: 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 | + |
| 89 | +text: BUILDER = text |
| 90 | +text: build |
| 91 | + @echo "Build finished; the text files are in build/text." |
| 92 | + |
| 93 | +texinfo: BUILDER = texinfo |
| 94 | +texinfo: 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 | + |
| 98 | +epub: BUILDER = epub |
| 99 | +epub: build |
| 100 | + @echo "Build finished; the epub files are in build/epub." |
| 101 | + |
| 102 | +changes: BUILDER = changes |
| 103 | +changes: build |
| 104 | + @echo "The overview file is in build/changes." |
| 105 | + |
| 106 | +linkcheck: BUILDER = linkcheck |
| 107 | +linkcheck: |
| 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 | + |
| 113 | +suspicious: BUILDER = suspicious |
| 114 | +suspicious: |
| 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 | + |
| 121 | +coverage: BUILDER = coverage |
| 122 | +coverage: build |
| 123 | + @echo "Coverage finished; see c.txt and python.txt in build/coverage" |
| 124 | + |
| 125 | +doctest: BUILDER = doctest |
| 126 | +doctest: |
| 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 | + |
| 132 | +pydoc-topics: BUILDER = pydoc-topics |
| 133 | +pydoc-topics: build |
| 134 | + @echo "Building finished; now run this:" \ |
| 135 | + "cp build/pydoc-topics/topics.py ../Lib/pydoc_data/topics.py" |
| 136 | + |
| 137 | +htmlview: html |
| 138 | + $(PYTHON) -c "import webbrowser; webbrowser.open('build/html/index.html')" |
| 139 | + |
| 140 | +clean: clean-venv |
| 141 | + -rm -rf build/* |
| 142 | + |
| 143 | +clean-venv: |
| 144 | + rm -rf $(VENVDIR) |
| 145 | + |
| 146 | +venv: |
| 147 | + @if [ -d $(VENVDIR) ] ; then \ |
| 148 | + echo "venv already exists."; \ |
| 149 | + echo "To recreate it, remove it first with \`make clean-venv'."; \ |
| 150 | + else \ |
| 151 | + $(PYTHON) -m venv $(VENVDIR); \ |
| 152 | + $(VENVDIR)/bin/python3 -m pip install -U pip setuptools; \ |
| 153 | + $(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \ |
| 154 | + echo "The venv has been created in the $(VENVDIR) directory"; \ |
| 155 | + fi |
| 156 | + |
| 157 | +dist: |
| 158 | + rm -rf dist |
| 159 | + mkdir -p dist |
| 160 | + |
| 161 | + # archive the HTML |
| 162 | + make html |
| 163 | + cp -pPR build/html dist/python-$(DISTVERSION)-docs-html |
| 164 | + tar -C dist -cf dist/python-$(DISTVERSION)-docs-html.tar python-$(DISTVERSION)-docs-html |
| 165 | + bzip2 -9 -k dist/python-$(DISTVERSION)-docs-html.tar |
| 166 | + (cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-html.zip python-$(DISTVERSION)-docs-html) |
| 167 | + rm -r dist/python-$(DISTVERSION)-docs-html |
| 168 | + rm dist/python-$(DISTVERSION)-docs-html.tar |
| 169 | + |
| 170 | + # archive the text build |
| 171 | + make text |
| 172 | + cp -pPR build/text dist/python-$(DISTVERSION)-docs-text |
| 173 | + tar -C dist -cf dist/python-$(DISTVERSION)-docs-text.tar python-$(DISTVERSION)-docs-text |
| 174 | + bzip2 -9 -k dist/python-$(DISTVERSION)-docs-text.tar |
| 175 | + (cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-text.zip python-$(DISTVERSION)-docs-text) |
| 176 | + rm -r dist/python-$(DISTVERSION)-docs-text |
| 177 | + rm dist/python-$(DISTVERSION)-docs-text.tar |
| 178 | + |
| 179 | + # archive the A4 latex |
| 180 | + rm -rf build/latex |
| 181 | + make latex PAPER=a4 |
| 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-a4.zip |
| 185 | + cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2 |
| 186 | + |
| 187 | + # archive the letter latex |
| 188 | + rm -rf build/latex |
| 189 | + make latex PAPER=letter |
| 190 | + -sed -i 's/makeindex/makeindex -q/' build/latex/Makefile |
| 191 | + (cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2) |
| 192 | + cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-letter.zip |
| 193 | + cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-letter.tar.bz2 |
| 194 | + |
| 195 | + # copy the epub build |
| 196 | + rm -rf build/epub |
| 197 | + make epub |
| 198 | + cp -pPR build/epub/Python.epub dist/python-$(DISTVERSION)-docs.epub |
| 199 | + |
| 200 | + # archive the texinfo build |
| 201 | + rm -rf build/texinfo |
| 202 | + make texinfo |
| 203 | + make info --directory=build/texinfo |
| 204 | + cp -pPR build/texinfo dist/python-$(DISTVERSION)-docs-texinfo |
| 205 | + tar -C dist -cf dist/python-$(DISTVERSION)-docs-texinfo.tar python-$(DISTVERSION)-docs-texinfo |
| 206 | + bzip2 -9 -k dist/python-$(DISTVERSION)-docs-texinfo.tar |
| 207 | + (cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-texinfo.zip python-$(DISTVERSION)-docs-texinfo) |
| 208 | + rm -r dist/python-$(DISTVERSION)-docs-texinfo |
| 209 | + rm dist/python-$(DISTVERSION)-docs-texinfo.tar |
| 210 | + |
| 211 | +check: |
| 212 | + $(PYTHON) tools/rstlint.py -i tools -i $(VENVDIR) -i README.rst |
| 213 | + |
| 214 | +serve: |
| 215 | + $(PYTHON) ../Tools/scripts/serve.py build/html |
| 216 | + |
| 217 | +# Targets for daily automated doc build |
| 218 | +# By default, Sphinx only rebuilds pages where the page content has changed. |
| 219 | +# This means it doesn't always pick up changes to preferred link targets, etc |
| 220 | +# To ensure such changes are picked up, we build the published docs with |
| 221 | +# `-E` (to ignore the cached environment) and `-a` (to ignore already existing |
| 222 | +# output files) |
| 223 | + |
| 224 | +# for development releases: always build |
| 225 | +autobuild-dev: |
| 226 | + make dist SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' |
| 227 | + -make suspicious |
| 228 | + |
| 229 | +# for quick rebuilds (HTML only) |
| 230 | +autobuild-dev-html: |
| 231 | + make html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' |
| 232 | + |
| 233 | +# for stable releases: only build if not in pre-release stage (alpha, beta) |
| 234 | +# release candidate downloads are okay, since the stable tree can be in that stage |
| 235 | +autobuild-stable: |
| 236 | + @case $(DISTVERSION) in *[ab]*) \ |
| 237 | + echo "Not building; $(DISTVERSION) is not a release version."; \ |
| 238 | + exit 1;; \ |
| 239 | + esac |
| 240 | + @make autobuild-dev |
| 241 | + |
| 242 | +autobuild-stable-html: |
| 243 | + @case $(DISTVERSION) in *[ab]*) \ |
| 244 | + echo "Not building; $(DISTVERSION) is not a release version."; \ |
| 245 | + exit 1;; \ |
| 246 | + esac |
| 247 | + @make autobuild-dev-html |
0 commit comments