forked from ITISFoundation/cookiecutter-osparc-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
104 lines (84 loc) · 2.88 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
#
# CONVENTIONS:
#
# - targets shall be ordered such that help list rensembles a typical workflow, e.g. 'make devenv tests'
# - add doc to relevant targets
# - internal targets shall start with '.'
# - KISS
#
SHELL = /bin/bash
.DEFAULT_GOAL := help
OUTPUT_DIR = $(CURDIR)/.output
TEMPLATE = $(CURDIR)
#-----------------------------------
.PHONY: devenv
.venv:
python3 -m venv $@
# upgrading package managers
$@/bin/pip install --upgrade \
pip \
wheel \
setuptools
# tooling
$@/bin/pip install pip-tools
requirements.txt: .venv requirements.in
# freezes requirements
$</bin/pip-compile --upgrade --build-isolation --output-file $@ $(word2, $^)
devenv: .venv requirements.txt ## create a python virtual environment with tools to dev, run and tests cookie-cutter
# installing extra tools
@$</bin/pip3 install -r $(word 2,$^)
# your dev environment contains
@$</bin/pip3 list
@echo "To activate the virtual environment, run 'source $</bin/activate'"
.PHONY: tests
tests: ## tests backed cookie
@pytest -vv \
--basetemp=$(CURDIR)/tmp \
--exitfirst \
--failed-first \
--durations=0 \
--pdb \
$(CURDIR)/tests
#-----------------------------------
.PHONY: play
$(OUTPUT_DIR):
# creating $@
@mkdir -p $@
define cookiecutterrc =
$(shell find $(OUTPUT_DIR) -name ".cookiecutterrc" 2>/dev/null | tail -n 1 )
endef
play: $(OUTPUT_DIR) ## runs cookiecutter into output folder
ifeq (,$(cookiecutterrc))
# baking cookie $(TEMPLATE) onto $<
@cookiecutter --output-dir "$<" "$(TEMPLATE)"
else
# replaying cookie-cutter using $(cookiecutterrc)
@cookiecutter --no-input -f \
--config-file="$(cookiecutterrc)" \
--output-dir="$<" "$(TEMPLATE)"
endif
@echo "To see generated code, lauch 'code $(OUTPUT_DIR)'"
.PHONY: version-patch version-minor version-major
version-patch version-minor version-major: ## commits version as patch (bug fixes not affecting the API), minor/minor (backwards-compatible/INcompatible API addition or changes)
# upgrades as $(subst version-,,$@) version, commits and tags
@bump2version --verbose --list $(subst version-,,$@)
#-----------------------------------
.PHONY: help
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## this colorful help
@echo "Recipes for '$(notdir $(CURDIR))':"
@echo ""
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
git_clean_args = -dxf --exclude=.vscode/ --exclude=.venv/
.PHONY: clean clean-force
clean: ## cleans all unversioned files in project and temp files create by this makefile
# Cleaning unversioned
@git clean -n $(git_clean_args)
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@echo -n "$(shell whoami), are you REALLY sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@git clean $(git_clean_args)
-rm -rf $(OUTPUT_DIR)
clean-force: clean
# removing .venv
-@rm -rf .venv