-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
249 lines (183 loc) · 5.64 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#
# Copyright 2017, Alexander Shorin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
PN = `python setup.py -q --name`
PV = `python setup.py -q --version`
SHELL = /bin/sh
SPHINXOPTS ?= -n -W
.PHONY: all
all: help
.PHONY: changelog
# target: changelog - Prints out upcoming release changelog
changelog:
@python setup.py -q changelog
.PHONY: check
# target: check - Checks project with the tests, linters and the rest tools
check: check-lint check-coverage
.PHONY: check-coverage
# target: check-coverage - Runs tests with coverage
check-coverage:
@python -m pytest --cov
.PHONY: check-lint
# target: check-lint - Check source code with linters
check-lint:
@python -m pytest -m 'flake8 or isort or pylint' \
--flake8 \
--isort \
--pylint --pylint-error-types=WEF --pylint-rcfile=.pylintrc
.PHONY: clean
# target: clean - Removes intermediate and generated files
clean:
@find . -type f -name '*.py[co]' -delete
@find . -type d -name '__pycache__' -delete
@rm -f .coverage
@rm -rf {build,htmlcov,cover,coverage}
@rm -rf src/*.egg-info
@rm -f RELEASE
@rm -f VERSION
@python setup.py clean
.PHONY: commit-changelog
commit-changelog:
@python setup.py changelog --update=CHANGELOG.rst
@python setup.py -q changelog --next-version > VERSION
@git rm changelog.d/*.rst
@git add CHANGELOG.rst
@git commit CHANGELOG.rst changelog.d/*.rst -m "Release `cat VERSION`"
.PHONY: coverage-report
# target: coverage-report - Prints coverage report
coverage-report:
@python -m coverage report
.PHONY: coverage-html
# target: coverage-html - Generates coverage HTML report
coverage-html:
@python -m coverage html
.PHONY: develop
# target: develop - Installs package in develop mode
develop:
@python -m pip install --upgrade pip setuptools wheel
@python -m pip install -e .[develop]
.PHONY: dist
dist: sdist wheel
.PHONY: distcheck
# target: distcheck - Verifies distributed artifacts
distcheck: sdist
@mkdir -p dist/$(PN)
@tar -xf dist/$(PN)-$(PV).tar.gz -C dist/$(PN) --strip-components=1
@$(MAKE) -C dist/$(PN) venv
@. dist/$(PN)/venv/bin/activate && pip install --upgrade setuptools
@. dist/$(PN)/venv/bin/activate && $(MAKE) -C dist/$(PN) develop
@. dist/$(PN)/venv/bin/activate && $(MAKE) -C dist/$(PN) check
@rm -rf dist/$(PN)
.PHONY: ensure-clean
ensure-clean:
@git diff --exit-code
@git diff --cached --exit-code
.PHONY: ensure-tag
ensure-tag:
@git describe --exact-match --tags $(git log -n1 --pretty='%h')
.PHONY: format
# target: format - Automatically formats the code according the common style
format:
@python -m isort.main -rc setup.py src/ tests/
@python -m autoflake -i -r \
--remove-all-unused-imports \
--remove-unused-variables \
setup.py \
src/ \
tests/
.PHONY: format-diff
# target: format-diff - Shows what will be done by `make format`
format-diff:
@python -m isort.main -df -rc setup.py src/ tests/
@python -m autoflake -r \
--remove-all-unused-imports \
--remove-unused-variables \
setup.py \
src/ \
tests/
.PHONY: fragment
# target: fragment - Generates changelog fragment using name and type parameters and commits it
fragment: new-fragment
@git commit changelog.d/$(name).$(type).rst
.PHONY: fragment-amend
# target: fragment-amend - Like target `fragment`, but amends file to HEAD commit
fragment-amend: new-fragment
@git commit --amend changelog.d/$(name).$(type).rst
.PHONY: help
# target: help - Prints this help
help:
@egrep "^# target: " Makefile \
| sed -e 's/^# target: //g' \
| sort -h \
| awk '{printf(" %-16s", $$1); $$1=$$2=""; print "-" $$0}'
.PHONY: install
# target: install - Install the project
install:
@pip install .
.PHONY: new-fragment
new-fragment: name ?= `git rev-parse --short HEAD`
new-fragment: type ?= misc
new-fragment:
@git show -s --format=%B HEAD > changelog.d/$(name).$(type).rst
@git add changelog.d/$(name).$(type).rst
.PHONY: pylint
# target: pylint - Generates pylint report
pylint:
@python -m pylint setup.py src/ tests/
.PHONY: purge
# target: purge - Removes all unversioned files and resets working copy
purge:
@git reset --hard HEAD
@git clean -xdff
.PHONY: release
# target: release - Makes a new release
release: ensure-clean \
distcheck \
release-notes \
dist \
commit-changelog \
tag-release
.PHONY: release-notes
release-notes:
@python setup.py -q changelog > RELEASE
@$(EDITOR) RELEASE
.PHONY: sdist
# target: sdist - Builds source distribution artifact
sdist: clean
@python setup.py sdist
.PHONY: tag-release
tag-release:
@git tag -s -F RELEASE `cat VERSION`
# target: venv - Creates virtual environment
venv:
@python -m venv venv
.PHONY: version
# target: version - Generates and prints project version in PEP-440 format
version: VERSION
@cat VERSION
VERSION:
@git describe --always --tags | sed -r 's/^(.*)-(.*)-(.*)/\1.\2+\3/' > $@
.PHONY: uninstall
# target: uninstall - Delete project installation
uninstall:
@pip uninstall $(PN)
.PHONY: upload
# target: upload - Uploads artifacts on PyPI
upload: ensure-clean ensure-tag sdist wheel
@python setup.py sdist bdist_wheel register upload
.PHONY: wheel
# target: wheel - Builds wheel artifact
wheel: clean
@python setup.py bdist_wheel