This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
200 lines (174 loc) · 5.61 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
# This file is part of the asdicts.
#
# Copyright (c) 2021 Serghei Iakovlev
#
# For the full copyright and license information, please view
# the LICENSE file that was distributed with this source code.
include default.mk
define mk-venv-link
@if [ -n "$(WORKON_HOME)" ]; then \
echo $(ROOT_DIR) > $(VENV_ROOT)/.project; \
if [ ! -d $(WORKON_HOME)/$(PKG_NAME) -a ! -L $(WORKON_HOME)/$(PKG_NAME) ]; \
then \
ln -s $(ROOT_DIR)/$(VENV_ROOT) $(WORKON_HOME)/$(PKG_NAME); \
echo ; \
echo Since you use virtualenvwrapper, we created a symlink; \
echo "so you can also use "workon $(PKG_NAME)" to activate the venv."; \
echo ; \
fi; \
fi
endef
define rm-venv-link
@if [ -n "$(WORKON_HOME)" ]; then \
if [ -L "$(WORKON_HOME)/$(PKG_NAME)" -a -f "$(WORKON_HOME)/$(PKG_NAME)" ]; \
then \
$(RM) $(WORKON_HOME)/$(PKG_NAME); \
fi; \
fi
endef
## Public targets
$(VENV_PYTHON): $(VENV_ROOT)
@echo
$(VENV_ROOT):
@echo $(CS)Creating a Python environment $(VENV_ROOT)$(CE)
$(PYTHON) -m venv --prompt $(PKG_NAME) $(VENV_ROOT)
@echo
@echo Done.
@echo
@echo To active it manually, run:
@echo
@echo " source $(VENV_BIN)/activate"
@echo
@echo See https://docs.python.org/3/library/venv.html for more.
@echo
$(call mk-venv-link)
.PHONY: init
init: $(VENV_PYTHON)
@echo $(CS)Installing dev requirements$(CE)
$(VENV_PYTHON) -m pip install --upgrade pip setuptools wheel
$(VENV_PIP) install --upgrade -r $(REQUIREMENTS)
.PHONY: install
install: init
@echo $(CS)Installing $(PKG_NAME)$(CE)
$(VENV_PIP) install --upgrade --editable .
.PHONY: uninstall
uninstall:
@echo $(CS)Uninstalling $(PKG_NAME)$(CE)
- $(VENV_PIP) uninstall --yes $(PKG_NAME) &2>/dev/null
@echo Done.
@echo
.PHONY: clean
clean:
@echo $(CS)Remove build and tests artefacts and directories$(CE)
$(RM) -r $(VENV_ROOT)
$(call rm-venv-link)
find ./ -name '__pycache__' -delete -o -name '*.pyc' -delete
$(RM) -r ./build ./dist ./*.egg-info
$(RM) -r ./.cache ./.pytest_cache
$(RM) -r ./htmlcov
$(RM) ./.coverage ./coverage.xml
.PHONY: check-dist
check-dist: $(VENV_PYTHON)
@echo $(CS)Check distribution files$(HEADER_EXTRA)$(CE)
$(VENV_BIN)/twine check ./dist/*
$(VENV_BIN)/check-wheel-contents ./dist/*.whl
@echo
.PHONY: test-ccov
test-ccov: COV=--cov=./$(PKG_NAME) --cov=./tests --cov-report=xml --cov-report=html
test-ccov: HEADER_EXTRA=' (with coverage)'
test-ccov: test
.PHONY: test-all
test-all: uninstall clean install test test-dist lint
.PHONY: test-dist
test-dist: test-sdist test-wheel
@echo
.PHONY: sdist
sdist:
@echo $(CS)Creating source distribution$(CE)
$(VENV_PYTHON) setup.py sdist
.PHONY: test-sdist
test-sdist: $(VENV_PYTHON) sdist
@echo $(CS)Testing source distribution and installation$(CE)
$(VENV_PIP) install --force-reinstall --upgrade dist/*.gz
@echo
$(VENV_PYTHON) -c "import $(PKG_NAME); print($(PKG_NAME).__version__)"
@echo
.PHONY: wheel
wheel: $(VENV_PYTHON)
@echo $(CS)Creating wheel distribution$(CE)
$(VENV_PYTHON) setup.py bdist_wheel
.PHONY: test-wheel
test-wheel: $(VENV_PYTHON) wheel
@echo $(CS)Testing built distribution and installation$(CE)
$(VENV_PIP) install --force-reinstall --upgrade dist/*.whl
@echo
$(VENV_PYTHON) -c "import $(PKG_NAME); print($(PKG_NAME).__version__)"
@echo
.PHONY: test
test: $(VENV_PYTHON)
@echo $(CS)Running tests$(HEADER_EXTRA)$(CE)
$(VENV_BIN)/py.test $(PYTEST_FLAGS) $(COV) ./$(PKG_NAME) ./tests
@echo
.PHONY: lint
lint: $(VENV_PYTHON)
@echo $(CS)Running linters$(CE)
-$(VENV_BIN)/flake8 $(FLAKE8_FLAGS) ./
$(VENV_BIN)/pylint ./$(PKG_NAME)
.PHONY: publish
publish: test-all upload
.PHONY: upload
upload: $(VENV_PYTHON)
@echo $(CS)Upload built distribution$(CE)
@$(VENV_PYTHON) setup.py --version | grep -q "dev" && echo '!!! Not publishing dev version !!!' && exit 1 || echo ok
$(MAKE) build
$(MAKE) check-dist
$(VENV_BIN)/twine upload ./dist/*
@echo
.PHONY: build
build: sdist wheel
@echo
.PHONY: help
help:
@echo $(PKG_NAME)
@echo
@echo 'Run "make init" first to install and update all dev dependencies.'
@echo 'See "default.mk" for variables you might want to set.'
@echo
@echo 'Available targets:'
@echo
@echo ' help: Show this help and exit'
@echo ' init: Installing dev requirements (has to be launched first)'
@echo ' install: Install development version of $(PKG_NAME)'
@echo ' uninstall: Uninstall local version of $(PKG_NAME)'
@echo ' build: Build $(PKG_NAME) distribution (sdist and wheel)'
@echo ' sdist: Create a source distribution'
@echo ' wheel: Create a wheel distribution'
@echo ' publish: Publish $(PKG_NAME) distribution to the repository'
@echo ' upload: Upload $(PKG_NAME) distribution to the repository (w/o tests)'
@echo ' clean: Remove build and tests artefacts and directories'
@echo ' check-dist: Check integrity of the distribution files and validate package'
@echo ' test: Run unit tests'
@echo ' test-dist: Testing package distribution and installation'
@echo ' test-sdist: Testing source distribution and installation'
@echo ' test-wheel: Testing built distribution and installation'
@echo ' test-all: Test everything'
@echo ' test-ccov: Run unit tests with coverage'
@echo ' lint: Lint the code'
@echo
@echo 'Virtualenv:'
@echo
@echo ' Python: $(VENV_PYTHON)'
@echo ' pip: $(VENV_PIP)'
@echo
@echo 'Flags:'
@echo
@echo ' FLAKE8_FLAGS: $(FLAKE8_FLAGS)'
@echo ' PYTEST_FLAGS: $(PYTEST_FLAGS)'
@echo
@echo 'Environment variables:'
@echo
@echo ' PYTHON: $(PYTHON)'
@echo ' WORKON_HOME: ${WORKON_HOME}'
@echo ' SHELL: $(shell echo $$SHELL)'
@echo ' TERM: $(shell echo $$TERM)'
@echo