-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
163 lines (144 loc) · 4.32 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
# This file is part of the Consumer API example.
#
# Copyright (C) 2023 Serghei Iakovlev <[email protected]>
#
# 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
requirements/%.txt: requirements/%.in $(VENV_BIN)
$(VENV_BIN)/pip-compile --allow-unsafe --generate-hashes --output-file=$@ $<
## Public targets
$(VENV_PYTHON): $(VENV_ROOT)
@echo
$(VENV_ROOT):
@echo $(CS)Creating a Python environment $(VENV_ROOT)$(CE)
$(VIRTUALENV) --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)Set up virtualenv$(CE)
$(VENV_PIP) install --progress-bar=off --upgrade pip pip-tools
@echo
.PHONY: install
install: $(REQUIREMENTS)
@echo $(CS)Installing $(PKG_NAME) and all its dependencies$(CE)
$(VENV_BIN)/pip-sync $^
$(VENV_PIP) install --upgrade --editable .
@echo
.PHONY: uninstall
uninstall:
@echo $(CS)Uninstalling $(PKG_NAME)$(CE)
- $(VENV_PIP) uninstall --yes $(PKG_NAME) &2>/dev/null
@echo Verifying...
cd .. && ! $(VENV_PYTHON) -m $(PKG_NAME) --version &2>/dev/null
@echo Done.
@echo
.PHONY: lint
lint: $(VENV_PYTHON)
@echo $(CS)Running linters$(CE)
-$(VENV_BIN)/flake8 $(FLAKE8_FLAGS) ./
$(VENV_BIN)/pylint $(PYLINT_FLAGS) ./$(PKG_NAME)
@echo
.PHONY: test
test: $(VENV_PYTHON)
@echo $(CS)Running tests$(CE)
$(VENV_BIN)/coverage erase
$(VENV_BIN)/coverage run -m pytest $(PYTEST_FLAGS) ./$(PKG_NAME) ./tests
@echo
.PHONY: ccov
ccov: $(VENV_PYTHON)
@echo $(CS)Combine coverage reports$(CE)
$(VENV_BIN)/coverage combine
$(VENV_BIN)/coverage report
$(VENV_BIN)/coverage html
$(VENV_BIN)/coverage xml
@echo
.PHONY: test-all
test-all: uninstall clean install test lint
.PHONY: clean
clean:
@echo $(CS)Remove build and tests artefacts and directories$(CE)
$(call rm-venv-link)
find ./ -name '__pycache__' -delete -o -name '*.pyc' -delete
$(RM) -r ./.cache ./.pytest_cache
$(RM) -r ./htmlcov
$(RM) ./coverage.*
@echo
.PHONY: maintainer-clean
maintainer-clean: clean
@echo $(CS)Performing full clean$(CE)
-$(RM) -r $(VENV_ROOT)
$(call rm-venv-link)
$(RM) requirements/*.txt
@echo
.PHONY: help
help:
@echo 'Consumer API example'
@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: Set up virtualenv (has to be launched first)'
@echo ' install: Install project and all its dependencies'
@echo ' uninstall: Uninstall local version of the project'
@echo ' lint: Lint the code'
@echo ' test: Run unit tests with coverage'
@echo ' ccov: Combine coverage reports'
@echo ' test-all: Test everything'
@echo ' clean: Remove build and tests artefacts and directories'
@echo ' maintainer-clean:'
@echo ' Delete almost everything that can be reconstructed'
@echo ' with this Makefile'
@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 ' PYLINT_FLAGS: $(PYLINT_FLAGS)'
@echo
@echo 'Environment variables:'
@echo
@echo ' PYTHON: $(PYTHON)'
@echo ' WORKON_HOME: ${WORKON_HOME}'
@echo ' VIRTUAL_ENV: ${VIRTUAL_ENV}'
@echo ' SHELL: $(shell echo $$SHELL)'
@echo ' TERM: $(shell echo $$TERM)'
@echo