-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
344 lines (272 loc) · 9.14 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
##############################################################################
# THIS FILE IS GENERATED BY MXMAKE
#
# DOMAINS:
#: applications.cookiecutter
#: core.base
#: core.mxenv
#: core.mxfiles
#: core.packages
#: core.sources
#
# SETTINGS (ALL CHANGES MADE BELOW SETTINGS WILL BE LOST)
##############################################################################
## core.base
# `deploy` target dependencies.
# No default value.
DEPLOY_TARGETS?=
# target to be executed when calling `make run`
# No default value.
RUN_TARGET?=
# Additional files and folders to remove when running clean target
# No default value.
CLEAN_FS?=
# Optional makefile to include before default targets. This can
# be used to provide custom targets or hook up to existing targets.
# Default: include.mk
INCLUDE_MAKEFILE?=include.mk
## core.mxenv
# Python interpreter to use.
# Default: python3
PYTHON_BIN?=python3
# Minimum required Python version.
# Default: 3.7
PYTHON_MIN_VERSION?=3.7
# Flag whether to use virtual environment. If `false`, the
# interpreter according to `PYTHON_BIN` found in `PATH` is used.
# Default: true
VENV_ENABLED?=true
# Flag whether to create a virtual environment. If set to `false`
# and `VENV_ENABLED` is `true`, `VENV_FOLDER` is expected to point to an
# existing virtual environment.
# Default: true
VENV_CREATE?=true
# The folder of the virtual environment.
# If `VENV_ENABLED` is `true` and `VENV_CREATE` is true it is used as the
# target folder for the virtual environment. If `VENV_ENABLED` is `true` and
# `VENV_CREATE` is false it is expected to point to an existing virtual
# environment. If `VENV_ENABLED` is `false` it is ignored.
# Default: venv
VENV_FOLDER?=venv
# mxdev to install in virtual environment.
# Default: mxdev
MXDEV?=mxdev
# mxmake to install in virtual environment.
# Default: mxmake
MXMAKE?=mxmake
## core.mxfiles
# The config file to use.
# Default: mx.ini
PROJECT_CONFIG?=mx.ini
##############################################################################
# END SETTINGS - DO NOT EDIT BELOW THIS LINE
##############################################################################
INSTALL_TARGETS?=
DIRTY_TARGETS?=
CLEAN_TARGETS?=
PURGE_TARGETS?=
# Defensive settings for make: https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
# for Makefile debugging purposes add -x to the .SHELLFLAGS
.SHELLFLAGS:=-eu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules
# mxmake folder
MXMAKE_FOLDER?=.mxmake
# Sentinel files
SENTINEL_FOLDER?=$(MXMAKE_FOLDER)/sentinels
SENTINEL?=$(SENTINEL_FOLDER)/about.txt
$(SENTINEL):
@mkdir -p $(SENTINEL_FOLDER)
@echo "Sentinels for the Makefile process." > $(SENTINEL)
##############################################################################
# mxenv
##############################################################################
# Check if given Python is installed
ifeq (,$(shell which $(PYTHON_BIN)))
$(error "PYTHON=$(PYTHON_BIN) not found in $(PATH)")
endif
# Check if given Python version is ok
PYTHON_VERSION_OK=$(shell $(PYTHON_BIN) -c "import sys; print((int(sys.version_info[0]), int(sys.version_info[1])) >= tuple(map(int, '$(PYTHON_MIN_VERSION)'.split('.'))))")
ifeq ($(PYTHON_VERSION_OK),0)
$(error "Need Python >= $(PYTHON_MIN_VERSION)")
endif
# Check if venv folder is configured if venv is enabled
ifeq ($(shell [[ "$(VENV_ENABLED)" == "true" && "$(VENV_FOLDER)" == "" ]] && echo "true"),"true")
$(error "VENV_FOLDER must be configured if VENV_ENABLED is true")
endif
# determine the executable path
ifeq ("$(VENV_ENABLED)", "true")
MXENV_PATH=$(VENV_FOLDER)/bin/
else
MXENV_PATH=
endif
MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel
$(MXENV_TARGET): $(SENTINEL)
ifeq ("$(VENV_ENABLED)", "true")
ifeq ("$(VENV_CREATE)", "true")
@echo "Setup Python Virtual Environment under '$(VENV_FOLDER)'"
@$(PYTHON_BIN) -m venv $(VENV_FOLDER)
endif
endif
@$(MXENV_PATH)pip install -U pip setuptools wheel
@$(MXENV_PATH)pip install -U $(MXDEV)
@$(MXENV_PATH)pip install -U $(MXMAKE)
@touch $(MXENV_TARGET)
.PHONY: mxenv
mxenv: $(MXENV_TARGET)
.PHONY: mxenv-dirty
mxenv-dirty:
@rm -f $(MXENV_TARGET)
.PHONY: mxenv-clean
mxenv-clean: mxenv-dirty
ifeq ("$(VENV_ENABLED)", "true")
ifeq ("$(VENV_CREATE)", "true")
@rm -rf $(VENV_FOLDER)
endif
else
@$(MXENV_PATH)pip uninstall -y $(MXDEV)
@$(MXENV_PATH)pip uninstall -y $(MXMAKE)
endif
INSTALL_TARGETS+=mxenv
DIRTY_TARGETS+=mxenv-dirty
CLEAN_TARGETS+=mxenv-clean
##############################################################################
# sources
##############################################################################
SOURCES_TARGET:=$(SENTINEL_FOLDER)/sources.sentinel
$(SOURCES_TARGET): $(PROJECT_CONFIG) $(MXENV_TARGET)
@echo "Checkout project sources"
@$(MXENV_PATH)mxdev -o -c $(PROJECT_CONFIG)
@touch $(SOURCES_TARGET)
.PHONY: sources
sources: $(SOURCES_TARGET)
.PHONY: sources-dirty
sources-dirty:
@rm -f $(SOURCES_TARGET)
.PHONY: sources-purge
sources-purge: sources-dirty
@rm -rf sources
INSTALL_TARGETS+=sources
DIRTY_TARGETS+=sources-dirty
PURGE_TARGETS+=sources-purge
##############################################################################
# mxfiles
##############################################################################
# case `core.sources` domain not included
SOURCES_TARGET?=
# File generation target
MXMAKE_FILES?=$(MXMAKE_FOLDER)/files
# set environment variables for mxmake
define set_mxfiles_env
@export MXMAKE_MXENV_PATH=$(1)
@export MXMAKE_FILES=$(2)
endef
# unset environment variables for mxmake
define unset_mxfiles_env
@unset MXMAKE_MXENV_PATH
@unset MXMAKE_FILES
endef
$(PROJECT_CONFIG):
ifneq ("$(wildcard $(PROJECT_CONFIG))","")
@touch $(PROJECT_CONFIG)
else
@echo "[settings]" > $(PROJECT_CONFIG)
endif
LOCAL_PACKAGE_FILES:=$(wildcard pyproject.toml setup.cfg setup.py requirements.txt constraints.txt)
FILES_TARGET:=requirements-mxdev.txt
$(FILES_TARGET): $(PROJECT_CONFIG) $(MXENV_TARGET) $(SOURCES_TARGET) $(LOCAL_PACKAGE_FILES)
@echo "Create project files"
@mkdir -p $(MXMAKE_FILES)
$(call set_mxfiles_env,$(MXENV_PATH),$(MXMAKE_FILES))
@$(MXENV_PATH)mxdev -n -c $(PROJECT_CONFIG)
$(call unset_mxfiles_env,$(MXENV_PATH),$(MXMAKE_FILES))
@test -e $(MXMAKE_FILES)/pip.conf && cp $(MXMAKE_FILES)/pip.conf $(VENV_FOLDER)/pip.conf || :
@touch $(FILES_TARGET)
.PHONY: mxfiles
mxfiles: $(FILES_TARGET)
.PHONY: mxfiles-dirty
mxfiles-dirty:
@touch $(PROJECT_CONFIG)
.PHONY: mxfiles-clean
mxfiles-clean: mxfiles-dirty
@rm -rf constraints-mxdev.txt requirements-mxdev.txt $(MXMAKE_FILES)
INSTALL_TARGETS+=mxfiles
DIRTY_TARGETS+=mxfiles-dirty
CLEAN_TARGETS+=mxfiles-clean
##############################################################################
# packages
##############################################################################
# additional sources targets which requires package re-install on change
-include $(MXMAKE_FILES)/additional_sources_targets.mk
ADDITIONAL_SOURCES_TARGETS?=
INSTALLED_PACKAGES=$(MXMAKE_FILES)/installed.txt
PACKAGES_TARGET:=$(INSTALLED_PACKAGES)
$(PACKAGES_TARGET): $(FILES_TARGET) $(ADDITIONAL_SOURCES_TARGETS)
@echo "Install python packages"
@$(MXENV_PATH)pip install -r $(FILES_TARGET)
@$(MXENV_PATH)pip freeze > $(INSTALLED_PACKAGES)
@touch $(PACKAGES_TARGET)
.PHONY: packages
packages: $(PACKAGES_TARGET)
.PHONY: packages-dirty
packages-dirty:
@rm -f $(PACKAGES_TARGET)
.PHONY: packages-clean
packages-clean:
@test -e $(FILES_TARGET) \
&& test -e $(MXENV_PATH)pip \
&& $(MXENV_PATH)pip uninstall -y -r $(FILES_TARGET) \
|| :
@rm -f $(PACKAGES_TARGET)
INSTALL_TARGETS+=packages
DIRTY_TARGETS+=packages-dirty
CLEAN_TARGETS+=packages-clean
##############################################################################
# cookiecutter
##############################################################################
COOKIECUTTER_TARGET:=$(SENTINEL_FOLDER)/cookiecutter.sentinel
$(COOKIECUTTER_TARGET): $(MXENV_TARGET)
@echo "Install cookiecutter"
@$(MXENV_PATH)pip install "cookiecutter>=2.1.1"
@touch $(COOKIECUTTER_TARGET)
.PHONY: cookiecutter-dirty
cookiecutter-dirty:
@rm -f $(COOKIECUTTER_TARGET)
.PHONY: cookiecutter-clean
cookiecutter-clean: cookiecutter-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y cookiecutter || :
@rm -f $(COOKIECUTTER_TARGET)
DIRTY_TARGETS+=cookiecutter-dirty
CLEAN_TARGETS+=cookiecutter-clean
-include $(INCLUDE_MAKEFILE)
##############################################################################
# Default targets
##############################################################################
INSTALL_TARGET:=$(SENTINEL_FOLDER)/install.sentinel
$(INSTALL_TARGET): $(INSTALL_TARGETS)
@touch $(INSTALL_TARGET)
.PHONY: install
install: $(INSTALL_TARGET)
@touch $(INSTALL_TARGET)
.PHONY: run
run: $(RUN_TARGET)
.PHONY: deploy
deploy: $(DEPLOY_TARGETS)
.PHONY: dirty
dirty: $(DIRTY_TARGETS)
@rm -f $(INSTALL_TARGET)
.PHONY: clean
clean: dirty $(CLEAN_TARGETS)
@rm -rf $(CLEAN_TARGETS) $(MXMAKE_FOLDER) $(CLEAN_FS)
.PHONY: purge
purge: clean $(PURGE_TARGETS)
.PHONY: runtime-clean
runtime-clean:
@echo "Remove runtime artifacts, like byte-code and caches."
@find . -name '*.py[c|o]' -delete
@find . -name '*~' -exec rm -f {} +
@find . -name '__pycache__' -exec rm -fr {} +