-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathMakefile
More file actions
226 lines (197 loc) · 5.98 KB
/
Makefile
File metadata and controls
226 lines (197 loc) · 5.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
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
SHELL=bash
# any files ending in .py?, and any folders named __pycache__
TEMPS=$(shell \
find intervaltree test \
\( -type f -name '*.py?' ! -path '*/__pycache__/*' \) \
-o \( -type d -name '__pycache__' \) \
)
PYTHON_MINORS:=$(shell echo 2.7 3.{5..14})
PYTHONS:=$(shell echo $(PYTHON_MINORS) | xargs -n1 pyenv latest -k)
# MAINPY and MAINPYMINOR are the latest python in the list.
# make install-devtools creates two venvs:
# - mainpy$(MAINPYMINOR), and
# - py$(MAINPYMINOR).
# mainpy is used for uploads to pypi. py is for running tests.
# All targets using source venv/... must ensure
# that subsequent lines are run using in the same shell.
MAINPY=$(shell echo $(PYTHONS) | tr ' ' '\n' | tail -n1)
MAINPYMINOR=$(shell echo $(PYTHON_MINORS) | tr ' ' '\n' | tail -n1)
PYPI=pypitest
# default target
all: test build
test: pytest flake8
quicktest:
source venv/py$(MAINPYMINOR)/bin/activate || true; \
python -m pytest
coverage:
source venv/py$(MAINPYMINOR)/bin/activate || true; \
python -m pytest --cov=intervaltree; \
python -m coverage html | \
sed -E 's@(Wrote HTML report to) (.*)@\1 file:/'"$$PWD"'/\2@'
pytest:
unset anyerr; \
for pyver in $(PYTHONS); do \
echo "pytest in Python $${pyver}"; \
pyminor=$${pyver%.*}; \
if ! source venv/py$${pyminor}/bin/activate; then \
echo "Failed to activate" >&2; \
anyerr=y; \
continue; \
fi; \
>/dev/null echo "Python 2.7 sends version to stderr instead of stdout"; \
if [[ "$$(python$${pyminor} --version 2>&1)" != *"Python $${pyver}" ]]; then \
echo "venv does not have Python $${pyver} installed" >&2; \
anyerr=y; \
continue; \
fi; \
if ! python$${pyminor} -m pytest; then \
echo "Pytest failed" >&2; \
anyerr=y; \
continue; \
fi; \
deactivate; \
done; \
if [ -n "$$anyerr" ]; then exit 1; fi
flake8:
source venv/py$(MAINPYMINOR)/bin/activate || true; \
python -m flake8 \
--count --statistics --select=E9,F63,F7,F82 --show-source \
--extend-exclude=venv,requirements,dist \
.; \
# python -m flake8 \
# --count --statistics --exit-zero \
# --max-complexity=10 --max-line-length=127 \
# --extend-exclude=venv,requirements,dist \
# .; \
deactivate
clean: clean-build clean-eggs clean-temps
distclean: clean clean-env
clean-build:
rm -rf dist build htmlcov
clean-eggs:
rm -rf *.egg* .eggs/
clean-env:
rm -rf venv
clean-temps:
rm -rf $(TEMPS)
# Project install/uninstall targets
install-testpypi:
pip install \
--no-cache-dir \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
intervaltree
install-pypi:
pip install intervaltree
install-develop:
pip install -e .
uninstall:
pip uninstall intervaltree sortedcontainers
# Setup for production upload
prod:
$(eval PYPI=pypi)
# Build wheel and sdist distribution
build: clean
source venv/mainpy$(MAINPYMINOR)/bin/activate; \
python$(MAINPYMINOR) -m hatch build; \
deactivate
upload: test build
source venv/mainpy$(MAINPYMINOR)/bin/activate; \
if [[ "$(PYPI)" == pypitest ]]; then \
python$(MAINPYMINOR) -m twine upload --verbose \
--repository testpypi \
dist/*; \
else \
python$(MAINPYMINOR) -m twine upload --verbose \
dist/*; \
fi; \
deactivate
install-devtools: pyenv-install-main-env pyenv-install-envs
pyenv-is-installed:
pyenv --version &>/dev/null || (echo "ERROR: pyenv not installed" && false)
# Set up an environment for running upload commands.
pyenv-install-main-env: pyenv-is-installed
@# echo N: Do not recompile a python interpreter if it is already present.
echo N | pyenv install $(MAINPY) || true
@echo "Setting up venv for main Python version $(MAINPY)"
export PYENV_VERSION=$(MAINPY)
unset CFLAGS;
python$(MAINPYMINOR) -m venv venv/mainpy$(MAINPYMINOR)
source venv/mainpy$(MAINPYMINOR)/bin/activate; \
pip$(MAINPYMINOR) install -U pip; \
pip$(MAINPYMINOR) install -U hatch twine; \
echo "Finished setting up venv for main Python $(MAINPY)"; \
deactivate
# Set up environments for running tests.
pyenv-install-envs: pyenv-is-installed
@# echo N: Do not recompile a python interpreter if it is already present.
for pyver in $(PYTHONS); do \
unset CFLAGS; \
if [[ "$$pyver" == 2.* ]]; then \
export CFLAGS=" -std=c17"; \
fi; \
echo N | pyenv install $$pyver || true; \
done
@# Setup virtual environments.
@# venv only works on Python 3.3 and later. It will not work for 2.7.
@# So, use virtualenv for 2.7.
for pyver in $(PYTHONS); do \
echo ""; \
echo "Setting up venv for Python $${pyver}"; \
export PYENV_VERSION=$$pyver; \
pyminor=$${pyver%.*}; \
if [[ "$$pyver" == 2.* ]]; then \
pip$${pyminor} install virtualenv || continue; \
python$${pyminor} -m virtualenv \
--python=python$${pyminor} \
venv/py$${pyminor} || continue; \
else \
python$${pyminor} -m venv venv/py$${pyminor} || continue; \
fi; \
source venv/py$${pyminor}/bin/activate || continue; \
pip$${pyminor} install -U pip || continue; \
pip$${pyminor} install -r requirements/pytest.txt || continue; \
if [[ "$${pyminor}" == "$(MAINPYMINOR)" ]]; then \
pip$${pyminor} install -r requirements/flake8.txt || continue; \
fi; \
echo "Finished setting up venv for Python $${pyver}"; \
deactivate \
done
pyenv-uninstall-versions:
for pyver in $(PYTHONS); do (echo y | pyenv uninstall $$pyver) || true; done
# for debugging the Makefile
env:
@echo
@echo MAINPY="\"$(MAINPY)\""
@echo MAINPYMINOR="\"$(MAINPYMINOR)\""
@echo PYTHONS="\"$(PYTHONS)\""
@echo PYTHON_MINORS="\"$(PYTHON_MINORS)\""
@echo CFLAGS="\"${CFLAGS}\""
@echo TEMPS="\"$(TEMPS)\""
@echo PYENV_VERSION="\"$${PYENV_VERSION}\""
@echo PYPI="\"$(PYPI)\""
.PHONY: all \
build \
clean \
clean-build \
clean-eggs \
clean-env \
clean-temps \
coverage \
distclean \
env \
flake8 \
install-develop \
install-devtools \
install-pypi \
install-testpypi \
prod \
pyenv-install-envs \
pyenv-install-main-env \
pyenv-is-installed \
pyenv-uninstall-versions \
pytest \
quicktest \
test \
uninstall \
upload