-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
216 lines (163 loc) · 5.79 KB
/
Makefile
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
NAME = dafpy
MAX_LINE_LENGTH = 120
ALL_SOURCE_FILES = $(shell git ls-files)
PY_SOURCE_FILES = $(filter %.py, $(ALL_SOURCE_FILES))
RST_SOURCE_FILES = $(filter %.rst, $(ALL_SOURCE_FILES))
DOCS_SOURCE_FILES = $(filter-out docs/v0.1.1/%, $(filter docs/%, $(ALL_SOURCE_FILES)))
.DEFAULT_GOAL := help
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help.replace('TODO-', 'TODO')))
endef
export PRINT_HELP_PYSCRIPT
help:
@python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
clean: clean-make clean-build clean-pyc clean-test clean-docs ## remove all build, test, coverage and Python artifacts
clean-make:
rm -fr .make.*
clean-build:
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
clean-pyc:
find . -name .mypy_cache -exec rm -fr {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
clean-test:
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
clean-docs:
rm -fr docs/v0.1.1
TODO = todo$()x
pc: $(TODO) ci staged ## check everything before commit
ci: format smells pytest docs dist ## check everything in a CI server
staged: ## check everything is staged for git commit
@if git status . | grep -q 'Changes not staged\|Untracked files'; \
then \
git status; \
echo 'There are unstaged changes (run `git add .`).'; \
false; \
else true; \
fi
format: trailingspaces linebreaks backticks fstrings isort black flake8 ## check code format
trailingspaces: .make.trailingspaces ## check for trailing spaces
REAL_SOURCE_FILES = \
$(filter-out %.png, \
$(filter-out %.svg, \
$(filter-out docs/v0.1.1/%, \
$(ALL_SOURCE_FILES))))
.make.trailingspaces: $(REAL_SOURCE_FILES)
@echo "trailingspaces"
@if grep -Hn '\s$$' $(REAL_SOURCE_FILES); \
then \
echo 'Files contain trailing spaces (run `make reformat` or `make stripspaces`).'; \
false; \
else true; \
fi
touch $@
linebreaks: .make.linebreaks ## check line breaks in Python code
.make.linebreaks: $(PY_SOURCE_FILES)
@echo "linebreaks"
@if grep -Hn "[^=*][^][/<>\"'a-zA-Z0-9_,:()#}{.?!\\=\`+-]$$" $(PY_SOURCE_FILES) | grep -v -- '--$$\|import \*$$'; \
then \
echo 'Files wrap lines after instead of before an operator (fix manually).'; \
false; \
fi
touch $@
backticks: .make.backticks ## check usage of backticks in documentation
.make.backticks: $(PY_SOURCE_FILES) $(RST_SOURCE_FILES)
@echo "backticks"
@OK=true; \
for FILE in $(PY_SOURCE_FILES) $(RST_SOURCE_FILES); \
do \
if ( sed 's/`genindex`/genindex/;s/``\([^`]*\)``/\1/g;s/`\([^`]*\)`_/\1_/g' "$$FILE" \
| grep --label "$$FILE" -n -H '`' \
) \
then OK=false; \
fi; \
done; \
if $$OK; \
then true; \
else \
echo 'Documentation contains invalid ` markers (fix manually).'; \
false; \
fi
touch $@
fstrings: .make.fstrings ## check f-strings in Python code
.make.fstrings: $(PY_SOURCE_FILES)
@echo "fstrings"
@if grep -Hn '^[^"]*\("\([^"]\|\\"\)*"[^"]*\)*[^f]"\([^"]\|\\"\)*{' $(PY_SOURCE_FILES) | grep -v 'NOT F-STRING'; \
then \
echo 'Strings appear to be f-strings, but are not (fix manually).'; \
false; \
fi
touch $@
isort: .make.isort ## check imports with isort
.make.isort: $(PY_SOURCE_FILES)
isort --line-length $(MAX_LINE_LENGTH) --force-single-line-imports --check $(NAME) tests
touch $@
$(TODO): .make.$(TODO) ## check there are no leftover TODO-X
.make.$(TODO): $(REAL_SOURCE_FILES)
@echo 'grep -n -i $(TODO) `git ls-files | grep -v pybind11`'
@if grep -n -i $(TODO) `git ls-files | grep -v pybind11`; \
then \
echo "Files contain $(TODO) markers (fix manually)."; \
false; \
else true; \
fi
touch $@
black: .make.black ## check format with black
.make.black: $(PY_SOURCE_FILES)
black --line-length $(MAX_LINE_LENGTH) --check $(NAME) tests
touch $@
flake8: .make.flake8 ## check format with flake8
.make.flake8: $(PY_SOURCE_FILES)
flake8 --max-line-length $(MAX_LINE_LENGTH) --ignore F401,E402,F403,W503,E704,E722,E501 $(NAME) tests
touch $@
reformat: stripspaces isortify blackify ## reformat code
stripspaces: # strip trailing spaces
@echo stripspaces
@for FILE in $$(grep -l '\s$$' $$(git ls-files | grep -v docs/v)); \
do sed -i -s 's/\s\s*$$//' $$FILE; \
done
isortify: ## sort imports with isort
isort --line-length $(MAX_LINE_LENGTH) --force-single-line-imports $(NAME) tests
blackify: ## reformat with black
black --line-length $(MAX_LINE_LENGTH) $(NAME) tests
smells: mypy pylint ## check for code smells
pylint: .make.pylint ## check code with pylint
.make.pylint: $(PY_SOURCE_FILES)
pylint --disable=fixme,protected-access,wrong-import-position,no-name-in-module,too-many-arguments,too-many-public-methods,too-few-public-methods,bare-except,line-too-long $(NAME) tests
touch $@
mypy: .make.mypy ## check code with mypy
.make.mypy: $(PY_SOURCE_FILES)
mypy $(NAME) tests
touch $@
pytest: .make.pytest ## run tests on the active Python with pytest
.make.pytest: $(PY_SOURCE_FILES)
`which pytest` -vv -s --cov=$(NAME) --cov-report=html --cov-report=term --no-cov-on-fail --maxfail=1 tests
touch $@
.PHONY: docs
docs: .make.docs ## generate HTML documentation
.make.docs: $(DOCS_SOURCE_FILES) $(PY_SOURCE_FILES) $(RST_SOURCE_FILES)
$(MAKE) -C docs clean
$(MAKE) -C docs html
sed -i 's/</\n</g' docs/v0.1.1/html/*.html
@echo "Results in docs/v0.1.1/html/index.html"
touch $@
dist: .make.dist ## builds the release distribution package
.make.dist: staged $(ALL_SOURCE_FILES)
rm -rf dist/
python3 setup.py sdist
twine check dist/*
touch $@
tags: $(PY_SOURCE_FILES) ## generate a tags file for vi
ctags $(PY_SOURCE_FILES)