|
| 1 | +# Minimal makefile for Sphinx documentation |
| 2 | +# |
| 3 | +# `Makefile.sp` is from the Sphinx starter pack and should not be |
| 4 | +# modified. |
| 5 | +# Add your customisation to `Makefile` instead. |
| 6 | + |
| 7 | +# You can set these variables from the command line, and also |
| 8 | +# from the environment for the first two. |
| 9 | +SPHINXDIR = .sphinx |
| 10 | +SPHINXOPTS ?= -c . -d $(SPHINXDIR)/.doctrees |
| 11 | +SPHINXBUILD ?= $(VENVDIR)/bin/sphinx-build |
| 12 | +SOURCEDIR = . |
| 13 | +BUILDDIR = _build |
| 14 | +VENVDIR = $(SPHINXDIR)/venv |
| 15 | +PA11Y = $(SPHINXDIR)/node_modules/pa11y/bin/pa11y.js --config $(SPHINXDIR)/pa11y.json |
| 16 | +VENV = $(VENVDIR)/bin/activate |
| 17 | +TARGET = * |
| 18 | +ALLFILES = *.rst **/*.rst |
| 19 | +
|
| 20 | +.PHONY: sp-full-help sp-woke-install sp-pa11y-install sp-install sp-run sp-html \ |
| 21 | + sp-epub sp-serve sp-clean sp-clean-doc sp-spelling sp-spellcheck sp-linkcheck sp-woke \ |
| 22 | + sp-pa11y Makefile.sp sp-vale |
| 23 | +
|
| 24 | +sp-full-help: $(VENVDIR) |
| 25 | + @. $(VENV); $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
| 26 | + @echo "\n\033[1;31mNOTE: This help texts shows unsupported targets!\033[0m" |
| 27 | + @echo "Run 'make help' to see supported targets." |
| 28 | +
|
| 29 | +# If requirements are updated, venv should be rebuilt and timestamped. |
| 30 | +$(VENVDIR): |
| 31 | + python3 -c "import venv" || \ |
| 32 | + (echo "You must install python3-venv before you can build the documentation."; exit 1) |
| 33 | + @echo "... setting up virtualenv" |
| 34 | + python3 -m venv $(VENVDIR) |
| 35 | + . $(VENV); pip install --require-virtualenv \ |
| 36 | + --upgrade -r $(SPHINXDIR)/requirements.txt \ |
| 37 | + --log $(VENVDIR)/pip_install.log |
| 38 | + @test ! -f $(VENVDIR)/pip_list.txt || \ |
| 39 | + mv $(VENVDIR)/pip_list.txt $(VENVDIR)/pip_list.txt.bak |
| 40 | + @. $(VENV); pip list --local --format=freeze > $(VENVDIR)/pip_list.txt |
| 41 | + @touch $(VENVDIR) |
| 42 | +
|
| 43 | +sp-woke-install: |
| 44 | + @type woke >/dev/null 2>&1 || \ |
| 45 | + { echo "Installing \"woke\" snap... \n"; sudo snap install woke; } |
| 46 | +
|
| 47 | +sp-pa11y-install: |
| 48 | + @type $(PA11Y) >/dev/null 2>&1 || { \ |
| 49 | + echo "Installing \"pa11y\" from npm... \n"; \ |
| 50 | + mkdir -p $(SPHINXDIR)/node_modules/ ; \ |
| 51 | + npm install --prefix $(SPHINXDIR) pa11y; \ |
| 52 | + } |
| 53 | +
|
| 54 | +sp-install: $(VENVDIR) |
| 55 | +
|
| 56 | +sp-run: sp-install |
| 57 | + . $(VENV); $(VENVDIR)/bin/sphinx-autobuild -b dirhtml "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) |
| 58 | +
|
| 59 | +# Doesn't depend on $(BUILDDIR) to rebuild properly at every run. |
| 60 | +sp-html: sp-install |
| 61 | + . $(VENV); $(SPHINXBUILD) -W --keep-going -b dirhtml "$(SOURCEDIR)" "$(BUILDDIR)" -w $(SPHINXDIR)/warnings.txt $(SPHINXOPTS) |
| 62 | +
|
| 63 | +sp-epub: sp-install |
| 64 | + . $(VENV); $(SPHINXBUILD) -b epub "$(SOURCEDIR)" "$(BUILDDIR)" -w $(SPHINXDIR)/warnings.txt $(SPHINXOPTS) |
| 65 | +
|
| 66 | +sp-serve: sp-html |
| 67 | + cd "$(BUILDDIR)"; python3 -m http.server --bind 127.0.0.1 8000 |
| 68 | +
|
| 69 | +sp-clean: sp-clean-doc |
| 70 | + @test ! -e "$(VENVDIR)" -o -d "$(VENVDIR)" -a "$(abspath $(VENVDIR))" != "$(VENVDIR)" |
| 71 | + rm -rf $(VENVDIR) |
| 72 | + rm -rf $(SPHINXDIR)/node_modules/ |
| 73 | + rm -rf $(SPHINXDIR)/styles |
| 74 | + rm -rf $(SPHINXDIR)/vale.ini |
| 75 | +
|
| 76 | +sp-clean-doc: |
| 77 | + git clean -fx "$(BUILDDIR)" |
| 78 | + rm -rf $(SPHINXDIR)/.doctrees |
| 79 | +
|
| 80 | +sp-spellcheck: |
| 81 | + . $(VENV) ; python3 -m pyspelling -c $(SPHINXDIR)/spellingcheck.yaml -j $(shell nproc) |
| 82 | +
|
| 83 | +sp-spelling: sp-html sp-spellcheck |
| 84 | +
|
| 85 | +sp-linkcheck: sp-install |
| 86 | + . $(VENV) ; $(SPHINXBUILD) -b linkcheck "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) || { grep --color -F "[broken]" "$(BUILDDIR)/output.txt"; exit 1; } |
| 87 | + exit 0 |
| 88 | +
|
| 89 | +sp-woke: sp-woke-install |
| 90 | + woke $(ALLFILES) --exit-1-on-failure \ |
| 91 | + -c https://github.com/canonical/Inclusive-naming/raw/main/config.yml |
| 92 | +
|
| 93 | +sp-pa11y: sp-pa11y-install sp-html |
| 94 | + find $(BUILDDIR) -name *.html -print0 | xargs -n 1 -0 $(PA11Y) |
| 95 | +
|
| 96 | +sp-vale: sp-install |
| 97 | + @. $(VENV); test -d $(SPHINXDIR)/venv/lib/python*/site-packages/vale || pip install vale |
| 98 | + @. $(VENV); test -f $(SPHINXDIR)/vale.ini || python3 $(SPHINXDIR)/get_vale_conf.py |
| 99 | + @. $(VENV); find $(SPHINXDIR)/venv/lib/python*/site-packages/vale/vale_bin -size 195c -exec vale --config "$(SPHINXDIR)/vale.ini" $(TARGET) > /dev/null \; |
| 100 | + @echo "" |
| 101 | + @echo "Running Vale against $(TARGET). To change target set TARGET= with make command" |
| 102 | + @echo "" |
| 103 | + @. $(VENV); vale --config "$(SPHINXDIR)/vale.ini" --glob='*.{md,txt,rst}' $(TARGET) |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +# Catch-all target: route all unknown targets to Sphinx using the new |
| 108 | +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). |
| 109 | +%: Makefile.sp |
| 110 | + . $(VENV); $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
0 commit comments