forked from jacebrowning/memegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
181 lines (136 loc) · 4.68 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
# Project settings
PROJECT := memegen
PACKAGE := memegen
REPOSITORY := jacebrowning/memegen
# Project paths
PACKAGES := $(PACKAGE) tests scripts
CONFIG := $(wildcard *.py)
MODULES := $(wildcard $(PACKAGE)/*.py)
# Virtual environment paths
export PIPENV_SHELL_COMPAT=true
export PIPENV_VENV_IN_PROJECT=true
export PIPENV_IGNORE_VIRTUALENVS=true
ENV := .venv
# MAIN TASKS ###################################################################
SNIFFER := pipenv run sniffer
.PHONY: all
all: install
.PHONY: ci
ci: check test validate ## Run all tasks that determine CI status
.PHONY: validate
validate: install
FLASK_CONFIG=test pipenv run python manage.py validate
.PHONY: watch
watch: install .clean-test ## Continuously run all CI tasks when files chanage
- pipenv run pip install MacFSEvents
$(SNIFFER)
# SERVER TARGETS ###############################################################
.PHONY: run
run: install ## Run the application
status=1; while [ $$status -eq 1 ]; do FLASK_ENV=dev pipenv run python manage.py run; status=$$?; sleep 1; done
.PHONY: launch
launch: install
sleep 3 && open http://localhost:5000 &
make run
.PHONY: run-prod
run-prod: install .env
pipenv shell "bin/post_compile; exit \$$?"
pipenv shell "heroku local web=1; exit \$$?"
.PHONY: launch-prod
launch-prod: install
sleep 5 && open http://localhost:5000 &
make run-prod
# SYSTEM DEPENDENCIES ##########################################################
.PHONY: doctor
doctor: ## Confirm system dependencies are available
bin/verchew
.env:
echo "FLASK_CONFIG=dev" >> $@
echo "GOOGLE_ANALYTICS_TID=local" >> $@
echo "#REGENERATE_IMAGES=true" >> $@
echo "WATERMARK_OPTIONS=localhost" >> $@
# PROJECT DEPENDENCIES #########################################################
DEPENDENCIES := $(ENV)/.pipenv-$(shell bin/checksum Pipfile*)
METADATA := *.egg-info
.PHONY: install
install: $(DEPENDENCIES)
$(DEPENDENCIES):
pipenv install --dev
@ touch $@
# CHECKS #######################################################################
PYLINT := pipenv run pylint
PYCODESTYLE := pipenv run pycodestyle
PYDOCSTYLE := pipenv run pydocstyle
.PHONY: check
check: pylint pycodestyle pydocstyle ## Run linters and static analysis
.PHONY: pylint
pylint: install
$(PYLINT) $(PACKAGES) $(CONFIG) --rcfile=.pylint.ini
.PHONY: pycodestyle
pycodestyle: install
$(PYCODESTYLE) $(PACKAGES) $(CONFIG) --config=.pycodestyle.ini
.PHONY: pydocstyle
pydocstyle: install
$(PYDOCSTYLE) $(PACKAGES) $(CONFIG)
# TESTS ########################################################################
PYTEST := pipenv run py.test
COVERAGE := pipenv run coverage
COVERAGE_SPACE := pipenv run coverage.space
RANDOM_SEED ?= $(shell date +%s)
FAILURES := .cache/v/cache/lastfailed
PYTEST_CORE_OPTIONS := -ra -vv
PYTEST_COV_OPTIONS := --cov=$(PACKAGE) --no-cov-on-fail --cov-report=term-missing:skip-covered --cov-report=html
PYTEST_RANDOM_OPTIONS := --random --random-seed=$(RANDOM_SEED)
PYTEST_OPTIONS := $(PYTEST_CORE_OPTIONS) $(PYTEST_RANDOM_OPTIONS)
ifndef DISABLE_COVERAGE
PYTEST_OPTIONS += $(PYTEST_COV_OPTIONS)
endif
PYTEST_RERUN_OPTIONS := $(PYTEST_CORE_OPTIONS) --last-failed --exitfirst
.PHONY: test
test: test-all ## Run unit and integration tests
.PHONY: test-unit
test-unit: install
@- mv $(FAILURES) $(FAILURES).bak
$(PYTEST) $(PYTEST_OPTIONS) $(PACKAGE)
@- mv $(FAILURES).bak $(FAILURES)
$(COVERAGE_SPACE) $(REPOSITORY) unit
.PHONY: test-int
test-int: install
@ if test -e $(FAILURES); then $(PYTEST) $(PYTEST_RERUN_OPTIONS) tests; fi
@ rm -rf $(FAILURES)
$(PYTEST) $(PYTEST_OPTIONS) tests
$(COVERAGE_SPACE) $(REPOSITORY) integration
.PHONY: test-all
test-all: install
@ if test -e $(FAILURES); then $(PYTEST) $(PYTEST_RERUN_OPTIONS) $(PACKAGES); fi
@ rm -rf $(FAILURES)
$(PYTEST) $(PYTEST_OPTIONS) $(PACKAGES)
$(COVERAGE_SPACE) $(REPOSITORY) overall
.PHONY: read-coverage
read-coverage:
bin/open htmlcov/index.html
# CLEANUP ######################################################################
.PHONY: clean
clean: .clean-test .clean-build ## Delete all generated and temporary files
.PHONY: clean-all
clean-all: clean .clean-env .clean-workspace
.PHONY: .clean-build
.clean-build:
find $(PACKAGES) -name '*.pyc' -delete
find $(PACKAGES) -name '__pycache__' -delete
rm -rf *.egg-info
.PHONY: .clean-test
.clean-test:
rm -rf .cache .pytest .coverage htmlcov
.PHONY: .clean-env
.clean-env: clean
rm -rf $(ENV)
.PHONY: .clean-workspace
.clean-workspace:
find data -name '*.tmp' -delete
rm -rf *.sublime-workspace
# HELP #########################################################################
.PHONY: help
help: all
@ grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help