|
| 1 | +# Makefile for Sphinx documentation |
| 2 | +# |
| 3 | + |
| 4 | +# You can set these variables from the command line. |
| 5 | +PYTHON = python3 |
| 6 | +VENVDIR = ./.venv |
| 7 | +SPHINXBUILD = $(VENVDIR)/bin/sphinx-build |
| 8 | +SPHINXOPTS = --fail-on-warning --keep-going |
| 9 | +BUILDDIR = _build |
| 10 | +BUILDER = html |
| 11 | +JOBS = auto |
| 12 | +SPHINXLINT = $(VENVDIR)/bin/sphinx-lint |
| 13 | + |
| 14 | +# Internal variables. |
| 15 | +ALLSPHINXOPTS = --builder $(BUILDER) \ |
| 16 | + --doctree-dir $(BUILDDIR)/doctrees \ |
| 17 | + --jobs $(JOBS) \ |
| 18 | + $(SPHINXOPTS) \ |
| 19 | + docs $(BUILDDIR)/$(BUILDER) |
| 20 | + |
| 21 | +.PHONY: help |
| 22 | +help: |
| 23 | + @echo "Please use \`make <target>' where <target> is one of" |
| 24 | + @echo " venv to create a venv with necessary tools" |
| 25 | + @echo " html to make standalone HTML files" |
| 26 | + @echo " htmlview to open the index page built by the html target in your browser" |
| 27 | + @echo " htmllive to rebuild and reload HTML files in your browser" |
| 28 | + @echo " clean to remove the venv and build files" |
| 29 | + @echo " linkcheck to check all external links for integrity" |
| 30 | + @echo " lint to lint all the files" |
| 31 | + |
| 32 | +.PHONY: clean |
| 33 | +clean: clean-venv |
| 34 | + -rm -rf $(BUILDDIR)/* |
| 35 | + |
| 36 | +.PHONY: clean-venv |
| 37 | +clean-venv: |
| 38 | + rm -rf $(VENVDIR) |
| 39 | + |
| 40 | +.PHONY: venv |
| 41 | +venv: |
| 42 | + @if [ -d $(VENVDIR) ] ; then \ |
| 43 | + echo "venv already exists."; \ |
| 44 | + echo "To recreate it, remove it first with \`make clean-venv'."; \ |
| 45 | + else \ |
| 46 | + $(MAKE) ensure-venv; \ |
| 47 | + fi |
| 48 | + |
| 49 | +.PHONY: ensure-venv |
| 50 | +ensure-venv: |
| 51 | + @if [ ! -d $(VENVDIR) ] ; then \ |
| 52 | + echo "Creating venv in $(VENVDIR)"; \ |
| 53 | + if uv --version > /dev/null; then \ |
| 54 | + uv venv $(VENVDIR); \ |
| 55 | + VIRTUAL_ENV=$(VENVDIR) uv pip install -r requirements.txt; \ |
| 56 | + else \ |
| 57 | + $(PYTHON) -m venv $(VENVDIR); \ |
| 58 | + $(VENVDIR)/bin/python3 -m pip install --upgrade pip; \ |
| 59 | + $(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \ |
| 60 | + fi; \ |
| 61 | + echo "The venv has been created in the $(VENVDIR) directory"; \ |
| 62 | + fi |
| 63 | + |
| 64 | +.PHONY: html |
| 65 | +html: ensure-venv |
| 66 | + $(SPHINXBUILD) $(ALLSPHINXOPTS) |
| 67 | + |
| 68 | +.PHONY: linkcheck |
| 69 | +linkcheck: BUILDER = linkcheck |
| 70 | +linkcheck: html |
| 71 | + @echo |
| 72 | + @echo "Link check complete; look for any errors in the above output " \ |
| 73 | + "or in $(BUILDDIR)/$(BUILDER)/output.txt." |
| 74 | + |
| 75 | +.PHONY: htmlview |
| 76 | +htmlview: html |
| 77 | + $(PYTHON) -c "import os, webbrowser; webbrowser.open('file://' + os.path.realpath('_build/html/index.html'))" |
| 78 | + |
| 79 | +.PHONY: htmllive |
| 80 | +htmllive: SPHINXBUILD = $(VENVDIR)/bin/sphinx-autobuild |
| 81 | +# Arbitrarily selected ephemeral port between 49152–65535 |
| 82 | +# to avoid conflicts with other processes: |
| 83 | +htmllive: SPHINXOPTS = --re-ignore="/\.idea/|/venv/" --open-browser --delay 0 --port 55303 |
| 84 | +htmllive: html |
| 85 | + |
| 86 | +.PHONY: lint |
| 87 | +lint: venv |
| 88 | + if uv --version > /dev/null; then \ |
| 89 | + $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || VIRTUAL_ENV=$(VENVDIR) uv pip install pre-commit; \ |
| 90 | + else \ |
| 91 | + $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit; \ |
| 92 | + fi; |
| 93 | + $(VENVDIR)/bin/python3 -m pre_commit run --all-files |
0 commit comments