-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
215 lines (173 loc) · 4.99 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
#
# Makefile: Commands to simplify development and releases
#
# Usage:
#
# make clean
# make checks
# make tests
# make patch build upload
# make minor build upload
# make major build upload
# This Makefile only works with GNU Make.
PYTHON = python3.12
# Where everything lives
site_python := /usr/bin/env $(PYTHON)
root_dir := $(realpath .)
src_dir = $(root_dir)/src/app_project
venv_name = venv
venv_dir = $(root_dir)/$(venv_name)
python = $(venv_dir)/bin/python
pip = $(python) -m pip
pip-compile = $(venv_dir)/bin/pip-compile
pip-sync = $(venv_dir)/bin/pip-sync
django = $(python) $(root_dir)/manage.py
flake8 = $(python) -m flake8
black = $(python) -m black
isort = $(python) -m isort
mypy = $(python) -m mypy
pytest = $(python) -m pytest
coverage = $(python) -m coverage
bumpversion = $(venv_dir)/bin/bump2version
tox = $(venv_dir)/bin/tox
twine = $(venv_dir)/bin/twine
# include additional targets or override variables from local makefiles
-include *.mk
.PHONY: help
help:
@echo "Please use 'make <target>' where <target> is one of:"
@echo
@echo " help to show this list"
@echo
@echo " clean-build to clean the files and directories generated by previous builds"
@echo " clean-coverage to clean the test coverage data and reports"
@echo " clean-mypy to clean the directory generated by mypy"
@echo " clean-docs to clean the generated HTML documentation"
@echo " clean-tests to clean the directories created during testing"
@echo " clean-venv to clean the virtualenv"
@echo " clean to clean everything EXCEPT the virtualenv"
@echo
@echo " venv to create the virtualenv"
@echo " install to install the project dependencies in the virtualenv"
@echo
@echo " checks to run code quality checks"
@echo " coverage to measure the test coverage"
@echo " tests to run the tests"
@echo " tox to run the tests for all the supported environments"
@echo
@echo " build to build the package"
@echo " docs to build the HTML documentation"
@echo
@echo " major to update the version number for a major release, e.g. 2.1 to 3.0"
@echo " minor to update the version number for a minor release, e.g. 2.1 to 2.2"
@echo " patch to update the version number for a patch release, e.g. 2.1.1 to 2.1.2"
@echo " upload to upload a release to PyPI repository"
@echo
# #########
# Clean
# #########
#
# Delete all the runtime files generated by the various targets,
# including the virtualenv.
.PHONY: clean-venv
clean-venv:
rm -rf $(venv_dir)
.PHONY: clean-build
clean-build:
rm -rf build
rm -rf src/*.egg-info
.PHONY: clean-docs
clean-docs:
cd docs && make clean
.PHONY: clean-tests
clean-tests:
rm -rf .tox
rm -rf .pytest_cache
.PHONY: clean-mypy
clean-mypy:
rm -rf .mypy_cache
.PHONY: clean-coverage
clean-coverage:
rm -rf .coverage
rm -rf coverage
.PHONY: clean
clean: clean-build clean-coverage clean-docs clean-mypy clean-tests
# ##############
# Virtualenv
# ##############
#
# Create the virtualenv and install all the dependencies for development.
# If the virtualenv already exists then synchronise the installed packages
# with those listed in requirements/dev.txt. The list of packages will be
# updated if any of the input files change.
$(venv_dir):
$(site_python) -m venv $(venv_dir)
$(pip) install --upgrade pip setuptools wheel
$(pip) install pip-tools
requirements/demo.txt: requirements/demo.in
$(pip-compile) requirements/demo.in
requirements/development.txt: requirements/development.in requirements/docs.in requirements/demo.in
$(pip-compile) requirements/development.in
requirements/docs.txt: requirements/docs.in
$(pip-compile) requirements/docs.in
requirements/test.txt: requirements/test.in requirements/demo.in
$(pip-compile) requirements/test.in
.PHONY: requirements
requirements: requirements/demo.txt requirements/development.txt requirements/docs.txt requirements/test.txt
.PHONY: venv
venv: $(venv_dir) requirements
$(pip-sync) requirements/development.txt
# ##########
# Checks
# ##########
.PHONY: flake8
flake8:
$(flake8) $(src_dir)
.PHONY: isort
isort:
$(isort) --check $(src_dir)
.PHONY: black
black:
$(black) --check $(src_dir)
.PHONY: mypy
mypy:
$(mypy) $(src_dir)
.PHONY: checks
checks: flake8 black isort mypy
# #########
# Tests
# #########
.PHONY: coverage
coverage:
$(pytest) --cov-config=setup.cfg --cov=$(src_dir) --cov-report html
.PHONY: tests
tests:
$(pytest)
.PHONY: tox
tox: test
$(tox)
$(tox) -e docs
# ########
# Docs
# ########
.PHONY: docs
docs:
cd docs && make html
# ###########
# Release
# ###########
.PHONY: build
build: clean-build
$(python) setup.py sdist bdist_wheel
.PHONY: major
major:
$(bumpversion) major
.PHONY: minor
minor:
$(bumpversion) minor
.PHONY: patch
patch:
$(bumpversion) patch
.PHONY: upload
upload:
$(twine) upload --skip-existing dist/*