Debian Codegraph @

Makefile

raw
1 SHELL := bash
2 .SHELLFLAGS := -eux -o pipefail -c
3 .DEFAULT_GOAL := build
4 .DELETE_ON_ERROR: # If a recipe to build a file exits with an error, delete the file.
5 .SUFFIXES: # Remove the default suffixes which are for compiling C projects.
6 .NOTPARALLEL: # Disable use of parallel subprocesses.
7 MAKEFLAGS += --warn-undefined-variables
8 MAKEFLAGS += --no-builtin-rules
9
10
11 export COLUMNS ?= 70
12 seperator ?= $(shell printf %${COLUMNS}s | tr " " "═")
13
14 platform := $(shell python -c 'import sys; print(sys.platform)')
15
16 PYTHON_VERSION ?= 3
17
18 export PIP_DISABLE_PIP_VERSION_CHECK=1
19 pip-install := ve/bin/pip --no-input install --constraint constraints.txt
20 pip-check := ve/bin/pip show -q
21
22 source_code := src
23
24 isort := ve/bin/isort --multi-line=VERTICAL_HANGING_INDENT --trailing-comma --no-sections
25
26 ########################################################################################
27 # Build targets
28 #
29 # It is acceptable for other targets to implicitly depend on these targets having been
30 # run. I.e., it is ok if "make lint" generates an error before "make" has been run.
31
32 .PHONY: build
33 build: ve development-utilities
34
35 ve:
36 python$(PYTHON_VERSION) -m venv ve
37
38 ve/bin/genbadge:
39 $(pip-install) genbadge[coverage]
40
41 ve/bin/%:
42 # Install development utility "$*"
43 $(pip-install) $*
44
45 # Utilities we use during development.
46 .PHONY: development-utilities
47 development-utilities: ve/bin/black
48 development-utilities: ve/bin/coverage
49 development-utilities: ve/bin/flake8
50 development-utilities: ve/bin/genbadge
51 development-utilities: ve/bin/isort
52 development-utilities: ve/bin/mypy
53 development-utilities: ve/bin/pydocstyle
54 development-utilities: ve/bin/pyinstaller
55 development-utilities: ve/bin/pylint
56 development-utilities: ve/bin/twine
57 development-utilities: ve/bin/wheel
58
59 ########################################################################################
60 # Distribution targets
61
62 .PHONY: assert-one-dist
63 assert-one-dist:
64 @if [ $$(find dist -name 'manuel-*.tar.gz' | wc -l) != 1 ]; then \
65 echo There must be one and only one distribution file present.; \
66 exit 1; \
67 fi
68
69 .PHONY: assert-no-unreleased-changes
70 assert-no-unreleased-changes:
71 @if grep unreleased CHANGES.rst > /dev/null; then \
72 echo There must not be any unreleased changes in CHANGES.rst.; \
73 exit 1; \
74 fi
75
76 .PHONY: assert-version-in-changelog
77 assert-version-in-changelog:
78 @if ! grep $$(ve/bin/python setup.py --version) CHANGES.rst; then \
79 echo The current version number must be mentioned in CHANGES.rst.; \
80 exit 1; \
81 fi
82
83 .PHONY: assert-matching-versions
84 assert-matching-versions:
85 # verify that the top-most version in the change log matches what is in setup.py
86 @env \
87 CHANGE_LOG_VERSION=$$(grep '^[^ ]\+ (20\d\d-\d\d-\d\d)' CHANGES.rst | head -n 1 | cut -d' ' -f1) \
88 SETUP_VERSION=$$(ve/bin/python setup.py --version) \
89 bash -c 'test $$CHANGE_LOG_VERSION = $$SETUP_VERSION'
90
91 .PHONY: assert-no-changes
92 assert-no-changes:
93 @if ! output=$$(git status --porcelain) || [ -n "$$output" ]; then \
94 echo There must not be any ucomitted changes.; \
95 exit 1; \
96 fi
97
98 .PHONY: dist
99 dist:
100 ve/bin/python setup.py sdist
101
102 .PHONY: test-dist
103 test-dist:
104 # check to see if the distribution passes the tests
105 rm -rf tmp
106 mkdir tmp
107 tar xzvf $$(find dist -name 'manuel-*.tar.gz') -C tmp
108 cd tmp/manuel-* && make && make check
109 rm -rf tmp
110
111 .PHONY: upload
112 upload: assert-one-dist
113 ve/bin/twine upload --repository manuel $$(find dist -name 'manuel-*.tar.gz')
114
115 .PHONY: badges
116 badges:
117 ve/bin/python bin/genbadge coverage -i coverage.xml -o badges/coverage-badge.svg
118
119 .PHONY: release
120 ifeq '$(shell git rev-parse --abbrev-ref HEAD)' 'master'
121 release: clean-dist assert-no-unreleased-changes assert-matching-versions \
122 assert-version-in-changelog badges dist assert-one-dist test-dist \
123 assert-no-changes upload
124 # now that a release has happened, tag the current HEAD as that release
125 git tag $$(ve/bin/python setup.py --version)
126 git push origin
127 git push origin --tags
128 else
129 release:
130 @echo Error: must be on master branch to do a release.; exit 1
131 endif
132
133 ########################################################################################
134 # Test and lint targets
135
136 .PHONY: pylint
137 pylint:
138 ve/bin/pylint $(source_code) --output-format=colorized
139
140 .PHONY: flake8
141 flake8:
142 ve/bin/flake8 $(source_code)
143
144 .PHONY: pydocstyle
145 pydocstyle:
146 ve/bin/pydocstyle $(source_code)
147
148 .PHONY: mypy
149 mypy:
150 ve/bin/mypy $(source_code) --strict
151
152 .PHONY: black-check
153 black-check:
154 ve/bin/black -S $(source_code) --check
155
156 .PHONY: isort-check
157 isort-check:
158 $(isort) $(source_code) --diff --check
159
160 .PHONY: lint
161 lint: black-check isort-check
162
163 .PHONY: test
164 test:
165 ve/bin/python setup.py test
166
167 .PHONY: coverage
168 coverage:
169 ve/bin/coverage run --branch setup.py test
170 ve/bin/coverage xml # the XML output file is used by the "badges" target
171 PYTHONWARNINGS=ignore ve/bin/coverage report --ignore-errors --fail-under=97 --show-missing --skip-empty
172
173 .PHONY: check
174 check: test lint coverage
175
176 ########################################################################################
177 # Sorce code formatting targets
178
179 .PHONY: black
180 black:
181 ve/bin/black -S $(source_code)
182
183 .PHONY: isort
184 isort:
185 $(isort) $(source_code)
186
187 ########################################################################################
188 # Cleanup targets
189
190 .PHONY: clean-%
191 clean-%:
192 rm -rf $*
193
194 .PHONY: clean-pycache
195 clean-pycache:
196 find . -name __pycache__ -delete
197
198 .PHONY: clean
199 clean: clean-ve clean-pycache clean-dist