forked from emailage/Emailage_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
340 lines (279 loc) · 8.93 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# Project settings
PROJECT := emailage-project
PACKAGE := emailage
SOURCES := Makefile setup.py $(shell find $(PACKAGE) -name '*.py')
# Python settings
ifndef TRAVIS
PYTHON_MAJOR ?= 2
PYTHON_MINOR ?= 7
endif
# Test settings
UNIT_TEST_COVERAGE := 88
INTEGRATION_TEST_COVERAGE := 47
COMBINED_TEST_COVERAGE := 100
# System paths
PLATFORM := $(shell python -c 'import sys; print(sys.platform)')
ifneq ($(findstring win32, $(PLATFORM)), )
WINDOWS := 1
SYS_PYTHON_DIR := C:\\Python$(PYTHON_MAJOR)$(PYTHON_MINOR)
SYS_PYTHON := $(SYS_PYTHON_DIR)\\python.exe
SYS_VIRTUALENV := $(SYS_PYTHON_DIR)\\Scripts\\virtualenv.exe
# https://bugs.launchpad.net/virtualenv/+bug/449537
export TCL_LIBRARY=$(SYS_PYTHON_DIR)\\tcl\\tcl8.5
else
ifneq ($(findstring darwin, $(PLATFORM)), )
MAC := 1
else
LINUX := 1
endif
SYS_PYTHON := python$(PYTHON_MAJOR)
ifdef PYTHON_MINOR
SYS_PYTHON := $(SYS_PYTHON).$(PYTHON_MINOR)
endif
SYS_VIRTUALENV := virtualenv
endif
# Virtual environment paths
ENV := env
ifneq ($(findstring win32, $(PLATFORM)), )
BIN := $(ENV)/Scripts
ACTIVATE := $(BIN)/activate.bat
OPEN := cmd /c start
else
BIN := $(ENV)/bin
ACTIVATE := . $(BIN)/activate
ifneq ($(findstring cygwin, $(PLATFORM)), )
OPEN := cygstart
else
OPEN := open
endif
endif
# Virtual environment executables
ifndef TRAVIS
BIN_ := $(BIN)/
endif
PYTHON := $(BIN_)python
PIP := $(BIN_)pip
EASY_INSTALL := $(BIN_)easy_install
RST2HTML := $(PYTHON) $(BIN_)rst2html.py
PDOC := $(PYTHON) $(BIN_)pdoc
MKDOCS := $(BIN_)mkdocs
PEP8 := $(BIN_)pep8
PEP8RADIUS := $(BIN_)pep8radius
PEP257 := $(BIN_)pep257
PYLINT := $(BIN_)pylint
PYREVERSE := $(BIN_)pyreverse
NOSE := $(BIN_)nosetests
PYTEST := $(BIN_)py.test
COVERAGE := $(BIN_)coverage
SNIFFER := $(BIN_)sniffer
HONCHO := $(ACTIVATE) && honcho
# Flags for PHONY targets
INSTALLED_FLAG := $(ENV)/.installed
DEPENDS_CI_FLAG := $(ENV)/.depends-ci
DEPENDS_DOC_FLAG := $(ENV)/.depends-doc
DEPENDS_DEV_FLAG := $(ENV)/.depends-dev
DOCS_FLAG := $(ENV)/.docs
ALL_FLAG := $(ENV)/.all
# Main Targets #################################################################
.PHONY: all
all: depends doc $(ALL_FLAG)
$(ALL_FLAG): $(SOURCES)
$(MAKE) check
touch $(ALL_FLAG) # flag to indicate all setup steps were successful
.PHONY: ci
ifdef TRAVIS
ci: check test tests
else
ci: doc check test tests
endif
.PHONY: watch
watch: depends .clean-test
@ rm -rf $(FAILED_FLAG)
$(SNIFFER)
# Development Installation #####################################################
.PHONY: env
env: $(PIP) $(INSTALLED_FLAG)
$(INSTALLED_FLAG): Makefile setup.py requirements.txt
VIRTUAL_ENV=$(ENV) $(PYTHON) setup.py develop
@ touch $(INSTALLED_FLAG) # flag to indicate package is installed
$(PIP):
$(SYS_VIRTUALENV) --python $(SYS_PYTHON) $(ENV)
$(PIP) install --upgrade pip setuptools
# Tools Installation ###########################################################
.PHONY: depends
depends: depends-ci depends-doc depends-dev
.PHONY: depends-ci
depends-ci: env Makefile $(DEPENDS_CI_FLAG)
$(DEPENDS_CI_FLAG): Makefile
$(PIP) install --upgrade pep8 pep257 pylint coverage pytest pytest-describe pytest-expecter pytest-cov pytest-random
@ touch $(DEPENDS_CI_FLAG) # flag to indicate dependencies are installed
.PHONY: depends-doc
depends-doc: env Makefile $(DEPENDS_DOC_FLAG)
$(DEPENDS_DOC_FLAG): Makefile
$(PIP) install --upgrade pylint docutils readme pdoc mkdocs pygments
@ touch $(DEPENDS_DOC_FLAG) # flag to indicate dependencies are installed
.PHONY: depends-dev
depends-dev: env Makefile $(DEPENDS_DEV_FLAG)
$(DEPENDS_DEV_FLAG): Makefile
$(PIP) install --upgrade pip pep8radius wheel sniffer
ifdef WINDOWS
$(PIP) install --upgrade pywin32
else ifdef MAC
$(PIP) install --upgrade pync MacFSEvents==0.4
else ifdef LINUX
$(PIP) install --upgrade pyinotify
endif
@ touch $(DEPENDS_DEV_FLAG) # flag to indicate dependencies are installed
# Documentation ################################################################
.PHONY: doc
doc: readme verify-readme uml apidocs mkdocs
.PHONY: doc-live
doc-live: doc
eval "sleep 3; open http://127.0.0.1:8000" &
$(MKDOCS) serve
.PHONY: read
read: doc
$(OPEN) site/index.html
$(OPEN) apidocs/$(PACKAGE)/index.html
$(OPEN) README-pypi.html
$(OPEN) README-github.html
.PHONY: readme
readme: depends-doc README-github.html README-pypi.html
README-github.html: README.md
pandoc -f markdown_github -t html -o README-github.html README.md
README-pypi.html: README.rst
$(RST2HTML) README.rst README-pypi.html
%.rst: %.md
pandoc -f markdown_github -t rst -o $@ $<
.PHONY: verify-readme
verify-readme: $(DOCS_FLAG)
$(DOCS_FLAG): README.rst CHANGES.rst
$(PYTHON) setup.py check --restructuredtext --strict --metadata
@ touch $(DOCS_FLAG) # flag to indicate README has been checked
.PHONY: uml
uml: depends-doc docs/*.png
docs/*.png: $(SOURCES)
$(PYREVERSE) $(PACKAGE) -p $(PROJECT) -a 1 -f ALL -o png --ignore test
- mv -f classes_$(PROJECT).png docs/classes.png
- mv -f packages_$(PROJECT).png docs/packages.png
.PHONY: apidocs
apidocs: depends-doc apidocs/$(PACKAGE)/index.html
apidocs/$(PACKAGE)/index.html: $(SOURCES)
$(PDOC) --html --overwrite $(PACKAGE) --html-dir apidocs
.PHONY: mkdocs
mkdocs: depends-doc site/index.html
site/index.html: mkdocs.yml docs/*.md
$(MKDOCS) build --clean --strict
# Static Analysis ##############################################################
.PHONY: check
check: pep8 pep257 pylint
.PHONY: pep8
pep8: depends-ci
$(PEP8) $(PACKAGE) tests --config=.pep8rc
.PHONY: pep257
pep257: depends-ci
$(PEP257) $(PACKAGE) tests
.PHONY: pylint
pylint: depends-ci
$(PYLINT) $(PACKAGE) tests --rcfile=.pylintrc
.PHONY: fix
fix: depends-dev
$(PEP8RADIUS) --docformatter --in-place
# Testing ######################################################################
RANDOM_SEED ?= $(shell date +%s)
PYTEST_CORE_OPTS := --doctest-modules -r xXw -vv
PYTEST_COV_OPTS := --cov=$(PACKAGE) --no-cov-on-fail --cov-report=term-missing
# PYTEST_RANDOM_OPTS := --random --random-seed=$(RANDOM_SEED)
PYTEST_OPTS := $(PYTEST_CORE_OPTS) $(PYTEST_COV_OPTS) $(PYTEST_RANDOM_OPTS)
PYTEST_OPTS_FAILFAST := $(PYTEST_OPTS) --failed --exitfirst
FAILURES := .cache/v/cache/lastfailed
.PHONY: test test-unit
test: test-unit
test-unit: depends-ci
@- mv $(FAILURES) $(FAILURES).bak
$(PYTEST) $(PYTEST_OPTS) $(PACKAGE)
@- mv $(FAILURES).bak $(FAILURES)
ifndef TRAVIS
$(COVERAGE) html --directory htmlcov --fail-under=$(UNIT_TEST_COVERAGE)
endif
.PHONY: test-int
test-int: depends-ci
@ if test -e $(FAILURES); then $(PYTEST) $(PYTEST_OPTS_FAILFAST) tests; fi
$(PYTEST) $(PYTEST_OPTS) tests
ifndef TRAVIS
$(COVERAGE) html --directory htmlcov --fail-under=$(INTEGRATION_TEST_COVERAGE)
endif
.PHONY: tests test-all
tests: test-all
test-all: depends-ci
@ if test -e $(FAILURES); then $(PYTEST) $(PYTEST_OPTS_FAILFAST) $(PACKAGE) tests; fi
$(PYTEST) $(PYTEST_OPTS) $(PACKAGE) tests
ifndef TRAVIS
$(COVERAGE) html --directory htmlcov --fail-under=$(COMBINED_TEST_COVERAGE)
endif
.PHONY: read-coverage
read-coverage:
$(OPEN) htmlcov/index.html
# Cleanup ######################################################################
.PHONY: clean
clean: .clean-dist .clean-test .clean-doc .clean-build
rm -rf $(ALL_FLAG)
.PHONY: clean-all
clean-all: clean .clean-env .clean-workspace
.PHONY: .clean-build
.clean-build:
find $(PACKAGE) tests -name '*.pyc' -delete
find $(PACKAGE) tests -name '__pycache__' -delete
rm -rf $(INSTALLED_FLAG) *.egg-info
.PHONY: .clean-doc
.clean-doc:
rm -rf README.rst apidocs *.html docs/*.png site
.PHONY: .clean-test
.clean-test:
rm -rf .cache .pytest .coverage htmlcov
.PHONY: .clean-dist
.clean-dist:
rm -rf dist build
.PHONY: .clean-env
.clean-env: clean
rm -rf $(ENV)
.PHONY: .clean-workspace
.clean-workspace:
rm -rf *.sublime-workspace
# Release ######################################################################
.PHONY: register-test
register-test: doc
$(PYTHON) setup.py register --strict --repository https://testpypi.python.org/pypi
.PHONY: upload-test
upload-test: register-test
$(PYTHON) setup.py sdist upload --repository https://testpypi.python.org/pypi
$(PYTHON) setup.py bdist_wheel upload --repository https://testpypi.python.org/pypi
$(OPEN) https://testpypi.python.org/pypi/$(PROJECT)
.PHONY: register
register: doc
$(PYTHON) setup.py register --strict
.PHONY: upload
upload: .git-no-changes register
$(PYTHON) setup.py sdist upload
$(PYTHON) setup.py bdist_wheel upload
$(OPEN) https://pypi.python.org/pypi/$(PROJECT)
.PHONY: .git-no-changes
.git-no-changes:
@ if git diff --name-only --exit-code; \
then \
echo Git working copy is clean...; \
else \
echo ERROR: Git working copy is dirty!; \
echo Commit your changes and try again.; \
exit -1; \
fi;
# System Installation ##########################################################
.PHONY: develop
develop:
$(SYS_PYTHON) setup.py develop
.PHONY: install
install:
$(SYS_PYTHON) setup.py install
.PHONY: download
download:
$(SYS_PYTHON) -m pip install $(PROJECT)