-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
215 lines (164 loc) · 5.59 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
# =========================================
# meta
# --------------------------------------
NAME := "connection_uri"
BRANCH := $(shell git for-each-ref --format='%(objectname) %(refname:short)' refs/heads | awk "/^$$(git rev-parse HEAD)/ {print \$$2}")
HASH := $(shell git rev-parse HEAD)
DATETIME := $(shell date | sed 's/ /./g')
PYTHON_2_VERSION := '2.7.13'
PYTHON_3_VERSION := '3.7.0'
# =========================================
# default
# --------------------------------------
all: test
# =========================================
# clean
# --------------------------------------
.PHONY: clean
clean:
CLEAR_PATTERNS='*.pyc __pycache__ build dist *.egg-info .eggs .tox'; \
for PATTERN in $$CLEAR_PATTERNS; do \
echo "rm -rf \$$(find $$PWD -name $$PATTERN)"; \
rm -rf $$(find $$PWD -name $$PATTERN); \
done
# =========================================
# install (pip)
# --------------------------------------
.PHONY: install
install:
PYTHON_USER_FLAG=$(shell python -c "import sys; print('' if hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix') else '--user')") && \
pip install $(PYTHON_USER_FLAG) -r requirements.txt
.PHONY: install-ci
install-ci:
PYTHON_USER_FLAG=$(shell python -c "import sys; print('' if hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix') else '--user')") && \
pip install $(PYTHON_USER_FLAG) -U setuptools setuptools-git setupextras tox tox-travis && \
pip install $(PYTHON_USER_FLAG) -r requirements.txt
# =========================================
# build + release (pip)
# --------------------------------------
.PHONY: build
build: package-build
.PHONY: release
release: package-release-dev package-release
.PHONY: release-dev
release: package-release-dev
.PHONY: package-build
package-build:
rm -rf ./dist && \
PYTHON_USER_FLAG=$(shell python -c "import sys; print('' if hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix') else '--user')") && \
python -m pip install $(PYTHON_USER_FLAG) --upgrade setuptools wheel && \
python setup.py sdist bdist_wheel
.PHONY: package-release
package-release: package-build
python -m pip install $(PYTHON_USER_FLAG) --upgrade twine && \
twine upload --repository pypi dist/*
.PHONY: package-release-dev
package-release-dev: package-build
python -m pip install $(PYTHON_USER_FLAG) --upgrade twine && \
twine upload --repository pypi-dev dist/*
# =========================================
# test
# --------------------------------------
.PHONY: test
test: test-python2 test-python3
test-python2: clean env2
eval "$$(pyenv init -)" && \
eval "$$(pyenv virtualenv-init -)" && \
pyenv activate $(NAME)-python2 && \
python ./$(NAME)/tests
test-python3: clean env3
eval "$$(pyenv init -)" && \
eval "$$(pyenv virtualenv-init -)" && \
pyenv activate $(NAME)-python3 && \
python ./$(NAME)/tests
.PHONY: test-tox
test-tox:
tox
.PHONY: test-ci
test-ci: test-tox coverage-ci
.PHONY: testimport
testimport:
pip uninstall -y $(NAME) && \
pip install -U . && \
python -c "import $(NAME); print('$(NAME)', $(NAME))" && \
echo "OK"
# =========================================
# coverage (codecov)
# --------------------------------------
.PHONY: coverage
coverage: clean env3
coverage run ./$(NAME)/tests
.PHONY: coverage-codecov
coverage-codecov: coverage
curl -s https://codecov.io/bash | bash
.PHONY: coverage-ci
coverage-ci:
coverage run ./$(NAME)/tests
.PHONY: coverage-ci-codecov
coverage-ci-codecov:
curl -s https://codecov.io/bash | bash
# =========================================
# environment (pyenv)
# --------------------------------------
.PHONY: env-install
env-install:
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
.PHONY: env-install-osx
env-install-osx:
brew install pyenv pyenv-virtualenv
.PHONY: env-install-linux
env-install-linux:
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
.PHONY: env-create
env-create: env-create-python2 env-create-python3
.PHONY: env-create-python2
env-create-python2:
eval "$$(pyenv init -)" && \
eval "$$(pyenv virtualenv-init -)" && \
pyenv virtualenv -f $(PYTHON_2_VERSION) $(NAME)-python2 && \
pyenv activate $(NAME)-python2 && \
pip install --upgrade pip && \
pip install -U -r requirements.txt && \
pyenv versions | grep --color=always $(NAME)-python
.PHONY: env-create-python3
env-create-python3:
eval "$$(pyenv init -)" && \
eval "$$(pyenv virtualenv-init -)" && \
pyenv virtualenv -f $(PYTHON_3_VERSION) $(NAME)-python3 && \
pyenv activate $(NAME)-python3 && \
pip install --upgrade pip && \
pip install -U -r requirements.txt && \
pyenv versions | grep --color=always $(NAME)-python
.PHONY: env-destroy
env-destroy: env-destroy-python2 env-destroy-python3
.PHONY: env-destroy-python2
env-destroy-python2:
eval "$$(pyenv init -)" && \
eval "$$(pyenv virtualenv-init -)" && \
pyenv shell system && \
pyenv uninstall -f $(NAME)-python2 && \
pyenv versions | grep --color=always $(NAME)-python
.PHONY: env-destroy-python3
env-destroy-python3:
eval "$$(pyenv init -)" && \
eval "$$(pyenv virtualenv-init -)" && \
pyenv shell system && \
pyenv uninstall -f $(NAME)-python3 && \
pyenv versions | grep --color=always $(NAME)-python
.PHONY: env-reset
env-reset:
pyenv shell system
.PHONY: env
env: env3
.PHONY: env2
env2:
eval "$$(pyenv init -)" && \
eval "$$(pyenv virtualenv-init -)" && \
pyenv activate $(NAME)-python2 && \
pyenv versions | grep --color=always $(NAME)-python
.PHONY: env3
env3:
eval "$$(pyenv init -)" && \
eval "$$(pyenv virtualenv-init -)" && \
pyenv activate $(NAME)-python3 && \
pyenv versions | grep --color=always $(NAME)-python