-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
351 lines (282 loc) · 13.4 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
341
342
343
344
345
346
347
348
349
350
351
#-------------------------------------------------------------------------------
# MASTER MAKEFILE FOR PYZENKIT PACKAGE
#
# This file is part of PyZenKit project (https://pypi.python.org/pypi/pyzenkit).
#
# Copyright (C) since 2015 CESNET, z.s.p.o (http://www.ces.net/)
# Copyright (C) since 2015 Honza Mach <[email protected]>
# Use of this package is governed by the MIT license, see LICENSE file.
#
# This project was initially written for personal use of the original author.
# Later it was developed much further and used for project of author`s employer.
#-------------------------------------------------------------------------------
#
# Default make target, alias for 'help', you must explicitly choose the target.
#
default: help
#===============================================================================
PROJECT_ID = pyzenkit
PROJECT_NAME = PyZenKit
DIR_LIB = $(shell realpath ./pyzenkit)
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXAPIDOC = sphinx-apidoc
SPHINXPROJ = $(PROJECT_NAME)
SPHINXSOURCEDIR = .
SPHINXBUILDDIR = doc/_build
SPHINXAPIDIR = doc/_doclib/apidoc
SPHINXAPIDOCFILES = $(SPHINXAPIDIR)/$(SPHINXPROJ).rst $(SPHINXAPIDIR)/modules.rst
VENV_PYTHON = python3
VENV_PATH = venv
PYTHON = python3
PIP = pip
NOSETESTS = nosetests
TWINE = twine
CURRENT_DIR = $(shell pwd)
#
# Include common makefile configurations.
#
include Makefile.inc
#
# Include local customized configurations.
#
include Makefile.cfg
#===============================================================================
help:
@echo ""
@echo " ██████╗ ██╗ ██╗███████╗███████╗███╗ ██╗██╗ ██╗██╗████████╗"
@echo " ██╔══██╗╚██╗ ██╔╝╚══███╔╝██╔════╝████╗ ██║██║ ██╔╝██║╚══██╔══╝"
@echo " ██████╔╝ ╚████╔╝ ███╔╝ █████╗ ██╔██╗ ██║█████╔╝ ██║ ██║ "
@echo " ██╔═══╝ ╚██╔╝ ███╔╝ ██╔══╝ ██║╚██╗██║██╔═██╗ ██║ ██║ "
@echo " ██║ ██║ ███████╗███████╗██║ ╚████║██║ ██╗██║ ██║ "
@echo " ╚═╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝ ╚═╝ "
@echo " $(FAINT)Copyright (C) since 2015 CESNET, z.s.p.o$(NC)"
@echo ""
@echo " $(GREEN)$(BOLD)╔══════════════════════════════════════════════════════════════════════════════════╗$(NC)"
@echo " $(GREEN)$(BOLD)║ LIST OF AVAILABLE MAKE TARGETS ║$(NC)"
@echo " $(GREEN)$(BOLD)╚══════════════════════════════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@echo " $(BLUE)$(BOLD)MAIN TARGETS$(NC)"
@echo " $(BLUE)$(BOLD)────────────$(NC)"
@echo " * $(GREEN)default$(NC): alias for help, you have to pick a target"
@echo " * $(GREEN)help$(NC): print this help and exit"
@echo " * $(GREEN)show-version$(NC): show current project version"
@echo " * $(GREEN)show-envstamp$(NC): show information about current development environment"
@echo " * $(GREEN)develop$(NC): install and configure project locally for development"
@echo " * $(GREEN)deps$(NC): install project dependencies"
@echo " * $(GREEN)clean$(NC): cleanup development and build environment"
@echo " * $(GREEN)docs$(NC): generate project documentation"
@echo " * $(GREEN)check$(NC): perform all checks and tests"
@echo " * $(GREEN)build-whl$(NC): perform local build of Python distribution package"
@echo " * $(GREEN)install-whl$(NC): perform local installation of Python distribution package"
@echo " * $(GREEN)release-whl$(NC): release Python distribution package to PyPI"
@echo ""
@echo " * $(GREEN)buildbot$(NC): build new distribution using buildbot automated system"
@echo ""
@echo " $(BLUE)$(BOLD)HELPER TARGETS$(NC)"
@echo " $(BLUE)$(BOLD)──────────────$(NC)"
@echo " * $(GREEN)deps-prerequisites$(NC): check for development prerequisites"
@echo " * $(GREEN)deps-lwchroot$(NC): creating local lightweight chroot subdirectory structure"
@echo " * $(GREEN)deps-python$(NC): install Python dependencies"
@echo " * $(GREEN)deps-python-dev$(NC): install Python development dependencies"
@echo " * $(GREEN)deps-editable$(NC): installing project in editable mode"
@echo " * $(GREEN)deps-python-upgrade$(NC): upgrade Python dependencies to latest versions"
@echo " * $(GREEN)deps-python-upgrade-dev$(NC): upgrade Python development dependencies to latest versions"
@echo ""
@echo " * $(GREEN)clean-pycs$(NC): clean up Python compiled files"
@echo " * $(GREEN)clean-build-docs$(NC): clean up documentation build directories"
@echo " * $(GREEN)clean-build-python$(NC): clean up Python build directories"
@echo ""
@echo " * $(GREEN)docs-apidocs$(NC): regenerate autogenerated Sphinx apidoc files"
@echo " * $(GREEN)docs-help$(NC): show list of all available html build targets"
@echo " * $(GREEN)docs-html$(NC): generate project documentation in HTML format"
@echo ""
@echo " * $(GREEN)pyflakes$(NC): check source code with pyflakes"
@echo " * $(GREEN)pylint$(NC): check source code with pylint"
@echo " * $(GREEN)test$(NC): run unit tests with nosetest"
@echo ""
@echo " * $(GREEN)build-package-whl$(NC): actually generate Python package"
@echo ""
@echo " $(GREEN)════════════════════════════════════════════════════════════════════════════════════$(NC)"
@echo ""
#
# Install and configure project locally for development. This target will perform
# following tasks for you:
# - bootstrap the Python virtual environment into 'venv' subdirectory
# - install all requirements (requirements.pip)
# - install all development requirements (requirements-dev.pip)
# - install the project in editable mode
#
# NOTE: This target is calling 'venv/bin/activate' on its own to install the
# requirements into newly created/existing virtual environment. When using all
# other makefile targets you must enable the environment youself!
#
develop: FORCE
@echo "\n$(GREEN)*** Installing Python virtual environment for local development ***$(NC)\n"
@echo "Requested version: $(VENV_PYTHON)"
@echo "Path to binary: `which $(VENV_PYTHON)`"
@echo "Path to venv: $(VENV_PATH)"
@echo ""
@if [ -d $(VENV_PATH) ]; then\
echo "$(CYAN)Virtual environment already exists in '$(VENV_PATH)'.$(NC)";\
else\
$(VENV_PYTHON) -m venv $(VENV_PATH);\
echo "$(CYAN)Virtual environment successfully created in '$(VENV_PATH)'.$(NC)";\
fi
@echo ""
@echo "Venv path: `. $(VENV_PATH)/bin/activate && python -c 'import sys; print(sys.prefix)'`"
@echo "Python stuff versions:"
@echo ""
@ls -al $(VENV_PATH)/bin | grep python
@ls -al $(VENV_PATH)/bin | grep pip
@echo "\n$(GREEN)*** Installing project requirements ***$(NC)\n"
@. $(VENV_PATH)/bin/activate && $(PIP) install -r requirements.pip
@echo "\n$(GREEN)*** Installing project development requirements ***$(NC)\n"
@. $(VENV_PATH)/bin/activate && $(PIP) install -r requirements-dev.pip
@echo "\n$(GREEN)*** Installing project into virtual environment in editable mode ***$(NC)\n"
@. $(VENV_PATH)/bin/activate && $(PIP) install -e .
@echo "\n$(GREEN)*** Creating local lightweight chroot directory structure ***$(NC)\n"
@mkdir -p ./chroot/tmp
@echo "\n$(CYAN)Your development environment is ready in `. $(VENV_PATH)/bin/activate && python -c 'import sys; print(sys.prefix)'`.$(NC)\n"
@echo "Please activate it manually with following command:\n"
@echo "\t$(ORANGE). $(VENV_PATH)/bin/activate$(NC)\n"
@echo "Consider adding following alias to your ~/.bashrc file for easier environment activation:\n"
@echo "\t$(ORANGE)alias entervenv='. venv/bin/activate'$(NC)\n"
@echo "$(BOLD)!!! Please keep in mind, that all makefile targets except this one ('develop') leave it up to you to activate the correct virtual environment !!!$(NC)"
@echo ""
#
# Install and configure project dependencies.
#
deps: deps-prerequisites deps-lwchroot deps-python deps-python-dev deps-editable
#
# Cleanup development and build environment.
#
clean: clean-pycs clean-build-python clean-build-docs
#
# Generate project documentation.
#
docs: docs-html
#
# Check the project code.
#
check: pyflakes pylint test
#
# Perform local build of Python distribution package.
#
build-whl: clean build-package-whl
#
# Install previously generated Python packages locally.
#
install-whl: FORCE
@echo "\n$(GREEN)*** Performing local installation of Python packages ***$(NC)\n"
@$(PIP) install dist/$(PROJECT_ID)*.whl --upgrade --force-reinstall
#
# Release previously generated Python packages to PyPI.
#
release-whl: FORCE
@echo "\n$(GREEN)*** Deploying packages to PyPI ***$(NC)\n"
@$(TWINE) upload dist/* --skip-existing
#-------------------------------------------------------------------------------
#
# Compatibility make targets.
#
#
# Perform local build.
#
build: build-whl
#
# Perfom build from automated system.
#
buildbot: build-whl
#-------------------------------------------------------------------------------
deps-prerequisites: FORCE
@echo "\n$(GREEN)*** Checking for development prerequisites ***$(NC)\n"
@for prereq in $(PYTHON) $(PIP) ; do \
if command -v $$prereq >/dev/null 2>&1; then \
echo "Prerequisite: $$prereq (`$$prereq --version | tr '\n' ',' | sed -e s/,$$//g;`)"; \
else \
echo "$(RED)PREREQUISITE: $$prereq (missing).$(NC)\n"; \
echo "You have to install this prerequisite manually.\n"; \
exit 1; \
fi \
done
@echo ""
deps-lwchroot: FORCE
@echo "\n$(GREEN)*** Creating local lightweight chroot subdirectory structure ***$(NC)\n"
@mkdir -p ./chroot/tmp
@echo ""
deps-python: FORCE
@echo "\n$(GREEN)*** Installing Python dependencies ***$(NC)\n"
@$(PIP) --version
@$(PIP) install -r requirements.pip --upgrade
@echo ""
deps-python-dev: FORCE
@echo "\n$(GREEN)*** Installing Python development dependencies ***$(NC)\n"
@$(PIP) --version
@$(PIP) install -r requirements-dev.pip
@echo ""
deps-editable: FORCE
@echo "\n$(GREEN)*** Installing project in editable mode ***$(NC)\n"
@$(PIP) --version
@$(PIP) install -e .
deps-python-upgrade: FORCE
@echo "\n$(GREEN)*** Upgrading Python dependencies to latest versions ***$(NC)\n"
@$(PIP) --version
@$(PIP) install -r requirements-latest.pip --upgrade
@echo ""
deps-python-upgrade-dev: FORCE
@echo "\n$(GREEN)*** Upgrading Python development dependencies to latest versions ***$(NC)\n"
@$(PIP) --version
@$(PIP) install -r requirements-latest-dev.pip --upgrade
@echo ""
#-------------------------------------------------------------------------------
clean-pycs: FORCE
@echo "\n$(GREEN)*** Cleaning up Python precompiled files ***$(NC)\n"
find . -name '*.pyc' -delete
find . -name '*.pyo' -delete
find . -name '*~' -delete
@echo ""
clean-build-python: FORCE
@echo "\n$(GREEN)*** Cleaning up Python build directories ***$(NC)\n"
rm --force --recursive --verbose build/
rm --force --recursive --verbose dist/
rm --force --recursive --verbose *.egg-info
@echo ""
clean-build-docs: FORCE
@echo "\n$(GREEN)*** Cleaning up documentation build directories ***$(NC)\n"
rm --force --recursive --verbose $(SPHINXBUILDDIR)/*
rm --force --recursive --verbose $(SPHINXAPIDIR)/*
@echo ""
#-------------------------------------------------------------------------------
docs-help: FORCE
@$(SPHINXBUILD) -M help "$(SPHINXSOURCEDIR)" "$(SPHINXBUILDDIR)" $(SPHINXOPTS) $(O)
docs-apidoc: FORCE
@echo "\n$(GREEN)*** Autogenerating project API documentation ***$(NC)\n"
@$(SPHINXAPIDOC) -e -o $(SPHINXAPIDIR) $(DIR_LIB)
docs-html: docs-apidoc FORCE
@echo "\n$(GREEN)*** Generating project documentation ***$(NC)\n"
@$(SPHINXBUILD) -M html "$(SPHINXSOURCEDIR)" "$(SPHINXBUILDDIR)" $(SPHINXOPTS) $(O)
#-------------------------------------------------------------------------------
pyflakes: FORCE
@echo "\n$(GREEN)*** Checking code with pyflakes ***$(NC)\n"
@$(PYTHON) --version
@echo ""
-@$(PYTHON) -m pyflakes $(DIR_LIB)
pylint: FORCE
@echo "\n$(GREEN)*** Checking code with pylint ***$(NC)\n"
@$(PYTHON) --version
@echo ""
-@$(PYTHON) -m pylint $(DIR_LIB) --rcfile .pylintrc
test: FORCE
@echo "\n$(GREEN)*** Checking code with nosetests ***$(NC)\n"
@$(NOSETESTS)
#-------------------------------------------------------------------------------
build-package-whl: FORCE
@echo "\n$(GREEN)*** Building Python packages ***$(NC)\n"
@echo "Python version: `$(PYTHON) --version`"
@echo ""
@$(PYTHON) setup.py sdist bdist_wheel
@echo ""
# Empty rule as dependency will force make to always perform target
# Source: https://www.gnu.org/software/make/manual/html_node/Force-Targets.html
FORCE: