Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
144 lines (118 loc) Β· 4.98 KB
/
Copy pathMakefile
File metadata and controls
144 lines (118 loc) Β· 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-eu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules
# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`
# Python checks
UV?=uv
# installed?
ifeq (, $(shell which $(UV) ))
$(error "UV=$(UV) not found in $(PATH)")
endif
BACKEND_FOLDER=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
VENV_FOLDER=$(BACKEND_FOLDER)/.venv
# Documentation
DOCS_DIR=docs
DOCS_BUILDDIR=$(DOCS_DIR)/_build
DOCS_SPHINXOPTS?=
DOCS_VALEOPTS?=
# Read the Docs sets it; a local run of docs-rtd writes here instead.
READTHEDOCS_OUTPUT?=$(DOCS_BUILDDIR)/rtd
DOCS_VALEFILES=$(shell find $(DOCS_DIR) -type f -name "*.md" -not -path "$(DOCS_BUILDDIR)/*" -not -path "$(DOCS_DIR)/_styles/*" -print)
BIN_FOLDER=$(VENV_FOLDER)/bin
all: build
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
$(VENV_FOLDER): ## Install dependencies
@echo "$(GREEN)==> Install environment$(RESET)"
@uv sync
.PHONY: install
install: $(VENV_FOLDER) ## Install the project
.PHONY: clean
clean: ## Clean environment
@echo "$(RED)==> Cleaning environment and build$(RESET)"
rm -rf $(VENV_FOLDER) .python-version .ruff_cache .pytest_cache uv.lock
# QA
.PHONY: lint
lint: $(VENV_FOLDER) ## Check code base according to our standards
@echo "$(GREEN)==> Lint codebase$(RESET)"
@uvx ruff@latest check --fix --config $(BACKEND_FOLDER)/pyproject.toml
@uvx pyroma@latest -d .
@uvx check-python-versions@latest .
@uv run mypy src
.PHONY: format
format: $(VENV_FOLDER) ## Fix code base according to our standards
@echo "$(GREEN)==> Format codebase$(RESET)"
@uvx ruff@latest check --select I --fix --config $(BACKEND_FOLDER)/pyproject.toml
@uvx ruff@latest format --config $(BACKEND_FOLDER)/pyproject.toml
.PHONY: check
check: format lint ## Check and fix code base according to Plone standards
############################################
# Tests
############################################
.PHONY: test
test: $(VENV_FOLDER) ## Test the code with pytest
@echo "π Testing code: Running pytest"
@uv run pytest
.PHONY: test-coverage
test-coverage: $(VENV_FOLDER) ## Test the code with pytest
@echo "π Testing code: Running pytest"
@uv run pytest --cov=repoplone --cov-report term-missing
############################################
# Documentation
############################################
.PHONY: docs
docs: $(VENV_FOLDER) ## Build the documentation (warnings are errors)
@echo "$(GREEN)==> Build documentation$(RESET)"
@uv run --group docs sphinx-build -W --keep-going -b html $(DOCS_DIR) "$(DOCS_BUILDDIR)/html" $(DOCS_SPHINXOPTS)
.PHONY: docs-rtd
docs-rtd: $(VENV_FOLDER) ## Build the pull request preview on Read the Docs (same build as docs)
@echo "$(GREEN)==> Build documentation preview$(RESET)"
@uv run --group docs sphinx-build -W --keep-going -b html $(DOCS_DIR) "$(READTHEDOCS_OUTPUT)/html" $(DOCS_SPHINXOPTS)
.PHONY: docs-livehtml
docs-livehtml: $(VENV_FOLDER) ## Rebuild the documentation on changes, with live reload in the browser
@uv run --group docs sphinx-autobuild --ignore "*.swp" --port 8050 -b html $(DOCS_DIR) "$(DOCS_BUILDDIR)/html" $(DOCS_SPHINXOPTS)
.PHONY: docs-linkcheck
docs-linkcheck: $(VENV_FOLDER) ## Check that all links in the documentation resolve
@echo "$(GREEN)==> Check documentation links$(RESET)"
@uv run --group docs sphinx-build -b linkcheck $(DOCS_DIR) "$(DOCS_BUILDDIR)/linkcheck"
.PHONY: docs-vale
docs-vale: $(VENV_FOLDER) ## Check the documentation with Vale
@echo "$(GREEN)==> Check documentation with Vale$(RESET)"
@uv run --group docs vale sync
@uv run --group docs vale --no-wrap $(DOCS_VALEOPTS) $(DOCS_VALEFILES)
.PHONY: docs-generate
docs-generate: $(VENV_FOLDER) ## Regenerate the command line reference
@echo "$(GREEN)==> Generate the command line reference$(RESET)"
@uv run --group docs python docs/_generate/cli.py
.PHONY: docs-generate-check
docs-generate-check: $(VENV_FOLDER) ## Fail when the command line reference is out of date
@echo "$(GREEN)==> Check the command line reference$(RESET)"
@uv run --group docs python docs/_generate/cli.py --check
.PHONY: docs-clean
docs-clean: ## Remove the built documentation
rm -rf "$(DOCS_BUILDDIR)"
############################################
# Release
############################################
.PHONY: changelog
changelog: $(VENV_FOLDER) ## Display a draft of the changelog
@echo "π Display the draft for the changelog"
@uv run towncrier --draft
.PHONY: release
release: $(VENV_FOLDER) ## Release the package with RepoPlone (make release VERSION=2.0.0)
@echo "π Release package"
@uv run repoplone release $(VERSION)