Repository navigation
Expand file tree
/
Copy pathMakefile.linux.example
More file actions
227 lines (204 loc) · 5.88 KB
/
Copy pathMakefile.linux.example
File metadata and controls
227 lines (204 loc) · 5.88 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#
# SPDX-FileCopyrightText: 2024-2026 Franco Masotti (See /README.md)
#
# SPDX-License-Identifier: MIT
ARCH := $$(uname --kernel-name --kernel-release --kernel-version --machine)
PYTHON_VERSION := $$(python --version)
PIP_VERSION_MAJOR := $$(pip --version | awk '{print $$2}' | cut --delimiter='.' --fields=1)
# See
# https://docs.python.org/3/library/venv.html#how-venvs-work
VENV_NEW := python3 -m venv .venv
VENV_ACTIVATE := . .venv/bin/activate
VENV_DEACTIVATE := deactivate
LOCK_DEV_FILENAME := $$(uname -s | tr '[:upper:]' '[:lower:]')-py$$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')-requirements-dev.lock
LOCK_FILENAME := $$(uname -s | tr '[:upper:]' '[:lower:]')-py$$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')-requirements.lock
# Version 26 instroduced `--uploaded-prior-to`.
ifeq ($(shell test $(PIP_VERSION_MAJOR) -ge 26 && echo true),true)
PIP_ARGS := --pip-args="--uploaded-prior-to=$$(date -d '-3days' -Idate)"
else
PIP_ARGS :=
endif
include .project.mk
default: install-dev
# Build the docs if the directory exists.
doc::
ifeq ($(OVERRIDE_DOC),)
ifeq ($(wildcard docs/.),)
@echo 'error: no docs available'
@exit 1
else
$(VENV_ACTIVATE) \
&& $(MAKE) -C docs html; \
$(VENV_DEACTIVATE)
endif
endif
# pip-audit and pip-tools must always be in the dev dependencies.
# Install anyway even if vulnerabilities are found: just tell it to the user.
install-dev:: uninstall-dev
ifeq ($(OVERRIDE_INSTALL_DEV),)
$(VENV_NEW) \
&& $(VENV_ACTIVATE) \
&& pip install \
--require-hashes \
--require-venv \
--requirement=$(LOCK_DEV_FILENAME) \
&& pip-audit \
--strict \
--requirement $(LOCK_DEV_FILENAME); \
pip install \
--require-venv \
--no-deps \
--editable .; \
$(VENV_DEACTIVATE)
$(VENV_ACTIVATE) \
&& pre-commit install; \
$(VENV_DEACTIVATE)
$(VENV_ACTIVATE) \
&& pre-commit install --hook-type commit-msg; \
$(VENV_DEACTIVATE)
endif
# Always start with a fresh environment when regenating lock files.
regenerate-lock:: uninstall-dev
ifeq ($(OVERRIDE_REGENERATE_LOCK),)
$(VENV_NEW) \
&& $(VENV_ACTIVATE) \
&& pip install -e .[dev] \
&& pip-compile \
--generate-hashes \
--strip-extras \
--allow-unsafe pyproject.toml \
--output-file=$(LOCK_FILENAME) \
$(PIP_ARGS) \
&& pip-audit \
--strict \
--requirement $(LOCK_FILENAME); \
$(VENV_DEACTIVATE)
endif
regenerate-dev-lock:: uninstall-dev
ifeq ($(OVERRIDE_REGENERATE_DEV_LOCK),)
$(VENV_NEW) \
&& $(VENV_ACTIVATE) \
&& pip install -e .[dev] \
&& pip-compile \
--extra=dev \
--generate-hashes \
--strip-extras \
--allow-unsafe pyproject.toml \
--output-file=$(LOCK_DEV_FILENAME) \
$(PIP_ARGS) \
&& pip-audit \
--strict \
--requirement $(LOCK_DEV_FILENAME); \
$(VENV_DEACTIVATE)
endif
uninstall-dev::
ifeq ($(OVERRIDE_UNINSTALL_DEV),)
rm -rf .venv
endif
pre-commit-update:: install-dev
ifeq ($(OVERRIDE_UPDATE),)
$(VENV_ACTIVATE) \
&& pre-commit autoupdate \
--repo https://github.com/pre-commit/pre-commit-hooks \
--repo https://github.com/PyCQA/bandit \
--repo https://github.com/pycqa/isort \
--repo https://github.com/frnmst/md-toc \
--repo https://github.com/ljnsn/cz-conventional-gitmoji \
--repo https://github.com/jorisroovers/gitlint; \
$(VENV_DEACTIVATE)
endif
test:
ifeq ($(wildcard ${PYTHON_MODULE_NAME}/tests/tests.py),)
@echo 'error: no tests available'
@exit 1
else
$(VENV_ACTIVATE) \
&& tox run-parallel; \
$(VENV_DEACTIVATE)
endif
test-single:
ifeq ($(wildcard ${PYTHON_MODULE_NAME}/tests/tests.py),)
@echo 'error: no tests available'
@exit 1
else
$(VENV_ACTIVATE) \
&& python -m unittest discover --failfast --locals --verbose; \
$(VENV_DEACTIVATE)
endif
test-coverage:
ifeq ($(wildcard ${PYTHON_MODULE_NAME}/tests/tests.py),)
@echo 'error: no tests available'
@exit 1
else
$(VENV_ACTIVATE) \
&& coverage run --branch -m unittest discover --failfast --locals --verbose \
&& coverage html; \
$(VENV_DEACTIVATE)
endif
fuzzer:
ifeq ($(wildcard ${PYTHON_MODULE_NAME}/tests/fuzzer.py),)
@echo 'error: no fuzzer available'
@exit 1
else
$(VENV_ACTIVATE) \
&& tox run -e fuzzer; \
$(VENV_DEACTIVATE)
endif
pre-commit:
$(VENV_ACTIVATE) \
&& pre-commit run --all; \
$(VENV_DEACTIVATE)
demo:
ifeq ($(wildcard asciinema/.),)
@echo 'error: no demo available'
@exit 1
else
$(VENV_ACTIVATE) \
&& asciinema/$(PYTHON_MODULE_NAME)_asciinema_$$(git describe --tags $$(git rev-list --tags --max-count=1) | tr '.' '_')_demo.sh; \
$(VENV_DEACTIVATE)
endif
dist:
# Create a reproducible archive at least on the wheel.
# See
# https://bugs.python.org/issue31526
# https://bugs.python.org/issue38727
# https://github.com/pypa/setuptools/issues/1468
# https://github.com/pypa/setuptools/issues/2133
# https://reproducible-builds.org/docs/source-date-epoch/
docker build \
--no-cache \
-f Dockerfile.python3.13_hatchling.build \
--output ./dist .
upload:
$(VENV_ACTIVATE) \
&& twine upload --repository $(PROJECT_NAME) dist/*; \
$(VENV_DEACTIVATE)
clean::
ifeq ($(OVERRIDE_CLEAN),)
rm -rf build dist *.egg-info tests/benchmark-results
# Remove all markdown files except the readmes.
find -regex "\(.*/crash-[a-f0-9]+\|.*\.[mM][dD]\)$$" \
! -name 'README.md' \
! -name 'CONTRIBUTING.md' \
! -name 'SECURITY.md' \
! -name 'CHANGELOG.md' \
! -name 'API.md' \
! -path './.venv/*' \
! -path './.git/*' -type f -exec rm -f {} +
ifneq ($(wildcard docs/.),)
$(VENV_ACTIVATE) \
&& $(MAKE) -C docs clean; \
$(VENV_DEACTIVATE)
endif
endif
# This serves both as benchmark and as fuzzer.
benchmark:
ifeq ($(wildcard $(PYTHON_MODULE_NAME)/tests/benchmark.py),)
@echo 'error: no benchmark available'
@exit 1
else
$(VENV_ACTIVATE) \
&& python3 -m $(PYTHON_MODULE_NAME).tests.benchmark; \
$(VENV_DEACTIVATE)
endif
.PHONY: default doc install-dev uninstall-dev update test clean demo benchmark pre-commit regenerate-lock regenerate-dev-lock dist