This repository has been archived by the owner on May 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Makefile
203 lines (161 loc) · 4.7 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
# Python settings
ifndef TRAVIS
PYTHON_MAJOR := 2
PYTHON_MINOR := 7
endif
# Test runner settings
ifndef TEST_RUNNER
TEST_RUNNER := pytest
endif
# Project settings
PROJECT := centrifuge
PACKAGE := centrifuge
SOURCES := Makefile setup.py $(shell find $(PACKAGE) -name '*.py')
EGG_INFO := $(subst -,_,$(PROJECT)).egg-info
# System paths
PLATFORM := $(shell python -c 'import sys; print(sys.platform)')
ifneq ($(findstring win32, $(PLATFORM)), )
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
SYS_PYTHON := python$(PYTHON_MAJOR)
ifdef PYTHON_MINOR
SYS_PYTHON := $(SYS_PYTHON).$(PYTHON_MINOR)
endif
SYS_VIRTUALENV := virtualenv
endif
# virtualenv paths
ENV := env
ifneq ($(findstring win32, $(PLATFORM)), )
BIN := $(ENV)/Scripts
OPEN := cmd /c start
else
BIN := $(ENV)/bin
ifneq ($(findstring cygwin, $(PLATFORM)), )
OPEN := cygstart
else
OPEN := open
endif
endif
# virtualenv executables
PYTHON := $(BIN)/python
PIP := $(BIN)/pip
EASY_INSTALL := $(BIN)/easy_install
RST2HTML := $(PYTHON) $(BIN)/rst2html.py
PDOC := $(PYTHON) $(BIN)/pdoc
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
# Remove if you don't want pip to cache downloads
PIP_CACHE_DIR := .cache
PIP_CACHE := --download-cache $(PIP_CACHE_DIR)
# Flags for PHONY targets
DEPENDS_CI := $(ENV)/.depends-ci
DEPENDS_DEV := $(ENV)/.depends-dev
ALL := $(ENV)/.all
# Main Targets ###############################################################
.PHONY: all
all: depends doc $(ALL)
$(ALL): $(SOURCES)
$(MAKE) check
touch $(ALL) # flag to indicate all setup steps were successful
.PHONY: ci
ci: test tests
# Development Installation ###################################################
.PHONY: env
env: .virtualenv $(EGG_INFO)
$(EGG_INFO): Makefile setup.py requirements.txt
VIRTUAL_ENV=$(ENV) $(PYTHON) setup.py develop
touch $(EGG_INFO) # flag to indicate package is installed
.PHONY: .virtualenv
.virtualenv: $(PIP)
$(PIP):
$(SYS_VIRTUALENV) --python $(SYS_PYTHON) $(ENV)
.PHONY: depends
depends: depends-ci depends-dev
.PHONY: depends-ci
depends-ci: env Makefile $(DEPENDS_CI)
$(DEPENDS_CI): Makefile
$(PIP) install $(PIP_CACHE) --upgrade pep8 pep257 pylint $(TEST_RUNNER) coverage mock
touch $(DEPENDS_CI) # flag to indicate dependencies are installed
.PHONY: depends-dev
depends-dev: env Makefile $(DEPENDS_DEV)
$(DEPENDS_DEV): Makefile
$(PIP) install $(PIP_CACHE) --upgrade pep8radius pygments docutils pdoc wheel
touch $(DEPENDS_DEV) # flag to indicate dependencies are installed
# Static Analysis ############################################################
.PHONY: check
check: pep8 pep257 pylint
.PHONY: pep8
pep8: depends-ci
$(PEP8) $(PACKAGE) --ignore=E501
.PHONY: pep257
pep257: depends-ci
$(PEP257) $(PACKAGE)
.PHONY: pylint
pylint: depends-ci
$(PYLINT) $(PACKAGE) --rcfile=.pylintrc
.PHONY: fix
fix: depends-dev
$(PEP8RADIUS) --docformatter --in-place
# Testing ####################################################################
.PHONY: test
test: test-$(TEST_RUNNER)
.PHONY: tests
tests: tests-$(TEST_RUNNER)
# pytest commands
.PHONY: test-pytest
test-pytest: depends-ci
$(COVERAGE) run --source $(PACKAGE) -m py.test test --doctest-modules
$(COVERAGE) report --show-missing --fail-under=10
.PHONY: tests-pytest
tests-pytest: depends-ci
TEST_INTEGRATION=1 $(MAKE) test
$(COVERAGE) report --show-missing --fail-under=10
# Cleanup ####################################################################
.PHONY: clean
clean: .clean-dist .clean-test .clean-doc .clean-build
rm -rf $(ALL)
.PHONY: clean-env
clean-env: clean
rm -rf $(ENV)
.PHONY: clean-all
clean-all: clean clean-env .clean-workspace .clean-cache
.PHONY: .clean-build
.clean-build:
find $(PACKAGE) -name '*.pyc' -delete
find $(PACKAGE) -name '__pycache__' -delete
rm -rf $(EGG_INFO)
.PHONY: .clean-doc
.clean-doc:
rm -rf README.rst apidocs docs/*.html docs/*.png
.PHONY: .clean-test
.clean-test:
rm -rf .coverage
.PHONY: .clean-dist
.clean-dist:
rm -rf dist build
.PHONY: .clean-cache
.clean-cache:
rm -rf $(PIP_CACHE_DIR)
.PHONY: .clean-workspace
.clean-workspace:
rm -rf *.sublime-workspace
# Release ####################################################################
.PHONY: dist
dist: check doc test tests
$(PYTHON) setup.py sdist
$(PYTHON) setup.py bdist_wheel
$(MAKE) read
.PHONY: upload
upload: .git-no-changes doc
$(PYTHON) setup.py register sdist upload
$(PYTHON) setup.py bdist_wheel upload