|
| 1 | +# Makefile for Sphinx documentation |
| 2 | +.DEFAULT_GOAL = help |
| 3 | +SHELL = bash |
| 4 | + |
| 5 | +# You can set these variables from the command line. |
| 6 | +SPHINXOPTS ?= |
| 7 | +PAPER ?= |
| 8 | + |
| 9 | +# Internal variables. |
| 10 | +GREEN=`tput setaf 2` |
| 11 | +RESET=`tput sgr0` |
| 12 | +DOCS_DIR = ./docs/ |
| 13 | +BUILDDIR = ./_build |
| 14 | +PAPEROPT_a4 = -D latex_paper_size=a4 |
| 15 | +PAPEROPT_letter = -D latex_paper_size=letter |
| 16 | +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(DOCS_DIR) |
| 17 | +VALEFILES := $(shell find $(DOCS_DIR) -type f -name "*.md" -print) |
| 18 | +VALEOPTS ?= |
| 19 | +PYTHONVERSION = >=3.11,<3.14 |
| 20 | + |
| 21 | +# Add the following 'help' target to your Makefile |
| 22 | +# And add help text after each target name starting with '\#\#' |
| 23 | +.PHONY: help |
| 24 | +help: # This help message |
| 25 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
| 26 | + |
| 27 | + |
| 28 | +# environment management |
| 29 | +.venv/bin/python: ## Create Python virtual environment and install package requirements |
| 30 | + @uv sync |
| 31 | + |
| 32 | +.PHONY: install |
| 33 | +install: .venv/bin/python ## Sync package requirements |
| 34 | + |
| 35 | + |
| 36 | +.PHONY: init |
| 37 | +init: clean clean-python .venv/bin/python ## Clean docs build directory and Python, and initialize Python virtual environment |
| 38 | + |
| 39 | +.PHONY: clean |
| 40 | +clean: ## Clean docs build directory |
| 41 | + cd $(DOCS_DIR) && rm -rf $(BUILDDIR)/ |
| 42 | + |
| 43 | +.PHONY: clean-python |
| 44 | +clean-python: clean |
| 45 | + rm -rf .venv/ |
| 46 | + rm -rf *.egg-info |
| 47 | +# /environment management |
| 48 | + |
| 49 | + |
| 50 | +# documentation builders |
| 51 | +.PHONY: html |
| 52 | +html: .venv/bin/python ## Build html |
| 53 | + @uv run sphinx-build -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html |
| 54 | + @echo |
| 55 | + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." |
| 56 | + |
| 57 | +.PHONY: livehtml |
| 58 | +livehtml: .venv/bin/python ## Rebuild Sphinx documentation on changes, with live-reload in the browser |
| 59 | + @uv run sphinx-autobuild \ |
| 60 | + --ignore "*.swp" \ |
| 61 | + --port 8050 \ |
| 62 | + -b html $(DOCS_DIR) "$(BUILDDIR)/html" $(SPHINXOPTS) $(O) |
| 63 | + |
| 64 | +.PHONY: dirhtml |
| 65 | +dirhtml: .venv/bin/python |
| 66 | + @uv run sphinx-build -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml |
| 67 | + @echo |
| 68 | + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." |
| 69 | + |
| 70 | +.PHONY: singlehtml |
| 71 | +singlehtml: .venv/bin/python |
| 72 | + @uv run sphinx-build -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml |
| 73 | + @echo |
| 74 | + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." |
| 75 | + |
| 76 | +.PHONY: text |
| 77 | +text: .venv/bin/python |
| 78 | + @uv run sphinx-build -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text |
| 79 | + @echo |
| 80 | + @echo "Build finished. The text files are in $(BUILDDIR)/text." |
| 81 | + |
| 82 | +.PHONY: changes |
| 83 | +changes: .venv/bin/python |
| 84 | + @uv run sphinx-build -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes |
| 85 | + @echo |
| 86 | + @echo "The overview file is in $(BUILDDIR)/changes." |
| 87 | + |
| 88 | +.PHONY: rtd-prepare |
| 89 | +rtd-prepare: ## Prepare environment on Read the Docs |
| 90 | + asdf plugin add uv |
| 91 | + asdf install uv latest |
| 92 | + asdf global uv latest |
| 93 | + |
| 94 | +.PHONY: rtd-pr-preview ## Build pull request previews on Read the Docs |
| 95 | +rtd-pr-preview: rtd-prepare .venv/bin/python ## Build pull request preview on Read the Docs |
| 96 | + cd $(DOCS_DIR) && $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) ${READTHEDOCS_OUTPUT}/html/ |
| 97 | +# /documentation builders |
| 98 | + |
| 99 | + |
| 100 | +# test |
| 101 | +.PHONY: linkcheck |
| 102 | +linkcheck: .venv/bin/python ## Run linkcheck |
| 103 | + @uv run sphinx-build -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck |
| 104 | + @echo |
| 105 | + @echo "Link check complete; look for any errors in the above output " \ |
| 106 | + "or in $(BUILDDIR)/linkcheck/ ." |
| 107 | + |
| 108 | +.PHONY: linkcheckbroken |
| 109 | +linkcheckbroken: .venv/bin/python ## Run linkcheck and show only broken links |
| 110 | + @uv run sphinx-build -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck | GREP_COLORS='0;31' grep -wi "broken\|redirect" --color=always | GREP_COLORS='0;31' grep -vi "https://github.com/plone/volto/issues/" --color=always && if test $$? = 0; then exit 1; fi || test $$? = 1 |
| 111 | + @echo |
| 112 | + @echo "Link check complete; look for any errors in the above output " \ |
| 113 | + "or in $(BUILDDIR)/linkcheck/ ." |
| 114 | + |
| 115 | +.PHONY: doctest |
| 116 | +doctest: .venv/bin/python ## Test snippets in the documentation |
| 117 | + @uv run sphinx-build -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest |
| 118 | + @echo "Testing of doctests in the sources finished, look at the " \ |
| 119 | + "results in $(BUILDDIR)/doctest/output.txt." |
| 120 | + |
| 121 | +.PHONY: vale |
| 122 | +vale: .venv/bin/python ## Run Vale style, grammar, and spell checks |
| 123 | + @uv run vale sync |
| 124 | + @uv run vale --no-wrap $(VALEOPTS) $(VALEFILES) |
| 125 | + @echo "Vale is finished; look for any errors in the above output." |
| 126 | + @echo |
| 127 | + |
| 128 | +.PHONY: test |
| 129 | +test: clean vale linkcheckbroken doctest ## Clean docs build, then run vale, linkcheckbroken, and doctest |
| 130 | + |
| 131 | +.PHONY: all |
| 132 | +all: clean vale linkcheckbroken html ## Clean docs build, then run linkcheckbroken, and build html |
| 133 | +# /test |
0 commit comments