-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMakefile
More file actions
222 lines (185 loc) · 7.61 KB
/
Makefile
File metadata and controls
222 lines (185 loc) · 7.61 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
########################################################
# Makefile for bitmath
#
# useful targets:
# make build ---------------- build sdist + wheel (output in dist/)
# make pypitest ------------- upload to TestPyPI (requires: pip install twine)
# make pypi ----------------- upload to PyPI (requires: pip install twine)
# make rpm ----------------- produce RPMs
# make docs ----------------- rebuild the docs
# make ci ----------------- run full test suite in virtualenv
########################################################
# > VARIABLE = value
#
# Normal setting of a variable - values within it are recursively
# expanded when the variable is USED, not when it's declared.
#
# > VARIABLE := value
#
# Setting of a variable with simple expansion of the values inside -
# values within it are expanded at DECLARATION time.
########################################################
NAME := bitmath
PKGNAME := python-$(NAME)
# VERSION file provides one place to update the software version.
VERSION := $(shell cat VERSION)
RPMRELEASE = $(shell awk '/global _short_release/{print $$NF; exit}' $(RPMSPEC).in)
RPMSPECDIR := .
RPMSPEC := $(RPMSPECDIR)/$(PKGNAME).spec
# This doesn't evaluate until it's called. The -D argument is the
# directory of the target file ($@), kinda like `dirname`.
ASCII2MAN = a2x -D $(dir $@) -d manpage -f manpage $<
ASCII2HTMLMAN = a2x -D docs/html/man/ -d manpage -f xhtml
MANPAGES := bitmath.1
######################################################################
# Begin make targets
######################################################################
# Documentation. YAY!!!!
DOCSVENV := bitmath2
docs-venv:
@if [ ! -d "$(DOCSVENV)" ]; then \
echo "Creating docs virtualenv '$(DOCSVENV)' with Python 3.12..."; \
python3.12 -m venv $(DOCSVENV); \
fi
. $(DOCSVENV)/bin/activate && pip install -q -r doc-requirements.txt
docs: docs-venv conf.py $(MANPAGES) docsite/source/index.rst
. $(DOCSVENV)/bin/activate && cd docsite && make html
# Add examples to the RTD docs by taking it from the README
docsite/source/index.rst: docsite/source/index.rst.in README.rst VERSION
@echo "#############################################"
@echo "# Building $@ Now"
@echo "#############################################"
awk 'BEGIN{P=0} /^Examples/ { P=1} { if (P == 1) print $$0 }' README.rst | cat $< - > $@
# Regenerate %.1.asciidoc if %.1.asciidoc.in has been modified more
# recently than %.1.asciidoc.
%.1.asciidoc: %.1.asciidoc.in VERSION
sed "s/%VERSION%/$(VERSION)/" $< > $@
# Regenerate %.1 if %.1.asciidoc or VERSION has been modified more
# recently than %.1. (Implicitly runs the %.1.asciidoc recipe)
%.1: %.1.asciidoc
@echo "#############################################"
@echo "# Building $@ NOW"
@echo "#############################################"
$(ASCII2MAN)
viewdocs: docs
@if [ "$$(uname)" = "Darwin" ]; then \
open docsite/build/html/index.html; \
elif echo "$$(uname)" | grep -qi "mingw\|cygwin\|msys"; then \
start docsite/build/html/index.html; \
else \
xdg-open docsite/build/html/index.html; \
fi
viewcover: ci-unittests
@if [ "$$(uname)" = "Darwin" ]; then \
open htmlcov/index.html; \
else \
xdg-open htmlcov/index.html; \
fi
conf.py: docsite/source/conf.py.in
sed "s/%VERSION%/$(VERSION)/" $< > docsite/source/conf.py
# Build the spec file on the fly. Substitute version numbers from the
# canonical VERSION file.
python-bitmath.spec: python-bitmath.spec.in
sed "s/%VERSION%/$(VERSION)/" $< > $@
build: clean
@echo "#############################################"
@echo "# Building sdist + wheel"
@echo "#############################################"
python -m build
pypi: build
@echo "#############################################"
@echo "# Uploading to PyPI"
@echo "#############################################"
twine upload dist/*
pypitest: build
@echo "#############################################"
@echo "# Uploading to TestPyPI"
@echo "#############################################"
twine upload --repository testpypi dist/*
# usage example: make tag TAG=1.1.0-1
tag:
git tag -s -m $(TAG) $(TAG)
clean:
@find . -type f -regex ".*\.py[co]$$" -delete
@find . -type f \( -name "*~" -or -name "#*" \) -delete
@rm -fR build cover dist rpm-build MANIFEST htmlcov .coverage bitmathenv3 docsite/build/html/ docsite/build/doctrees/ bitmath.egg-info
uniquetestnames:
@echo "#############################################"
@echo "# Running Unique TestCase checker"
@echo "#############################################"
./tests/test_unique_testcase_names.sh
install:
pip install .
mkdir -p /usr/share/man/man1/
gzip -9 -c bitmath.1 > /usr/share/man/man1/bitmath.1.gz
sdist: clean
@echo "#############################################"
@echo "# Creating SDIST"
@echo "#############################################"
python -m build --sdist
rpmcommon: sdist python-bitmath.spec
@echo "#############################################"
@echo "# Building (S)RPM Now"
@echo "#############################################"
@mkdir -p rpm-build
@cp dist/$(NAME)-$(VERSION).$(RPMRELEASE).tar.gz rpm-build/$(VERSION).$(RPMRELEASE).tar.gz
srpm: rpmcommon
rpmbuild --define "_topdir %(pwd)/rpm-build" \
--define "_builddir %{_topdir}" \
--define "_rpmdir %{_topdir}" \
--define "_srcrpmdir %{_topdir}" \
--define "_specdir $(RPMSPECDIR)" \
--define "_sourcedir %{_topdir}" \
-bs $(RPMSPEC)
@echo "#############################################"
@echo "$(PKGNAME) SRPM is built:"
@find rpm-build -maxdepth 2 -name '$(PKGNAME)*src.rpm' | awk '{print " " $$1}'
@echo "#############################################"
rpm: rpmcommon
rpmbuild --define "_topdir %(pwd)/rpm-build" \
--define "_builddir %{_topdir}" \
--define "_rpmdir %{_topdir}" \
--define "_srcrpmdir %{_topdir}" \
--define "_specdir $(RPMSPECDIR)" \
--define "_sourcedir %{_topdir}" \
-ba $(RPMSPEC)
@echo "#############################################"
@echo "$(PKGNAME) RPMs are built:"
@find rpm-build -maxdepth 2 -name '$(PKGNAME)*.rpm' | awk '{print " " $$1}'
@echo "#############################################"
virtualenv:
@echo ""
@echo "#############################################"
@echo "# Creating a virtualenv"
@echo "#############################################"
@if [ ! -d "$(NAME)env3" ]; then \
python3 -m venv $(NAME)env3; \
fi
. $(NAME)env3/bin/activate && python -m pip install --upgrade pip && pip install -r requirements.txt
ci-unittests: virtualenv
@echo ""
@echo "#############################################"
@echo "# Running Unit Tests in virtualenv"
@echo "# Using python: $(shell ./$(NAME)env3/bin/python --version 2>&1)"
@echo "#############################################"
. $(NAME)env3/bin/activate && pytest -v --cov=bitmath --cov-report term-missing --cov-report term:skip-covered --cov-report xml:coverage.xml --cov-report html:htmlcov tests
ci-list-deps:
@echo ""
@echo "#############################################"
@echo "# Listing all pip deps"
@echo "#############################################"
. $(NAME)env3/bin/activate && pip freeze
ci-pycodestyle:
@echo ""
@echo "#############################################"
@echo "# Running PEP8 Compliance Tests in virtualenv"
@echo "#############################################"
. $(NAME)env3/bin/activate && pycodestyle -v --ignore=E501,E722 bitmath/__init__.py tests/*.py
ci-flake8:
@echo ""
@echo "#################################################"
@echo "# Running Flake8 Compliance Tests in virtualenv"
@echo "#################################################"
. $(NAME)env3/bin/activate && flake8 --select=F bitmath/__init__.py tests/*.py
ci: clean uniquetestnames virtualenv ci-list-deps ci-pycodestyle ci-flake8 ci-unittests
: