forked from joshfriend/flask-restful-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
151 lines (113 loc) · 3.19 KB
/
Makefile
File metadata and controls
151 lines (113 loc) · 3.19 KB
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
# Python settings
PYTHON_MAJOR := 2
PYTHON_MINOR := 7
# Project settings (automatically detected from files/directories)
PROJECT := BarCampDemo
PACKAGE := demo
SOURCES := Makefile setup.py $(shell find $(PACKAGE) -name '*.py')
REQUIREMENTS_DEV := requirements/dev.txt
REQUIREMENTS_PROD := requirements/prod.txt
SYS_PYTHON := python$(PYTHON_MAJOR).$(PYTHON_MINOR)
SYS_VIRTUALENV := virtualenv
# virtualenv paths (automatically detected from the system Python)
ENV := env
BIN := $(ENV)/bin
# virtualenv executables
PYTHON := $(BIN)/python
PIP := $(BIN)/pip
PEP8 := $(BIN)/pep8
FLAKE8 := $(BIN)/flake8
PEP257 := $(BIN)/pydocstyle
PYLINT := $(BIN)/pylint
PYTEST := "$(BIN)/py.test"
COVERAGE := $(BIN)/coverage
ACTIVATE := $(BIN)/activate
HONCHO := . $(ACTIVATE); $(BIN)/honcho
HONCHO_CONFIG := .env
# Flags for PHONY targets
DEPENDS := $(ENV)/depends
ALL := $(ENV)/.all
# Main Targets ###############################################################
.PHONY: all
all: depends $(ALL)
$(ALL): $(SOURCES)
$(MAKE) check
touch $(ALL) # flag to indicate all setup steps were successful
.PHONY: ci
ci: pep8 pep257 test tests
# Development Installation ###################################################
.PHONY: env
env: .virtualenv
.PHONY: .virtualenv
.virtualenv: $(PIP)
$(PIP):
$(SYS_VIRTUALENV) --python $(SYS_PYTHON) $(ENV)
.PHONY: depends
depends: env $(DEPENDS)
$(DEPENDS): $(REQUIREMENTS_DEV) $(REQUIREMENTS_PROD)
$(PIP) install -r $(REQUIREMENTS_DEV)
touch $(DEPENDS) # flag to indicate dependencies are installed
# Static Analysis ############################################################
.PHONY: check
check: flake8
.PHONY: pep8
pep8: depends
$(PEP8) $(PACKAGE)
.PHONY: flake8
flake8: depends
$(FLAKE8) $(PACKAGE)
.PHONY: pep257
pep257: depends
$(PEP257) $(PACKAGE) --ignore=D102
.PHONY: pylint
pylint: depends
$(PYLINT) $(PACKAGE) --rcfile=.pylintrc
# Testing ####################################################################
.PHONY: test
test: depends
$(COVERAGE) run --source $(PACKAGE) -m py.test tests
$(COVERAGE) report -m
.PHONY: tests
tests: depends
TEST_INTEGRATION=1 $(COVERAGE) run --source $(PACKAGE) -m py.test tests
$(COVERAGE) report -m
# Development server #########################################################
define HONCHO_CONFIG_CONTENTS
GUNICORN_RELOAD=true
GUNICORN_WORKER_CLASS=gevent
endef
export HONCHO_CONFIG_CONTENTS
$(HONCHO_CONFIG):
echo "$$HONCHO_CONFIG_CONTENTS" > $@
.PHONY: serve
serve: depends $(HONCHO_CONFIG)
$(HONCHO) start -e $(HONCHO_CONFIG)
# Database Migrations ########################################################
.PHONY: migrate
migrate: depends
$(PYTHON) manage.py db migrate
.PHONY: upgrade
upgrade: depends
$(PYTHON) manage.py db upgrade
.PHONY: downgrade
downgrade: depends
$(PYTHON) manage.py db downgrade
# Cleanup ####################################################################
.PHONY: clean
clean: .clean-dist .clean-test .clean-build
rm -rf $(ALL)
.PHONY: clean-all
clean-all: clean .clean-env
.PHONY: .clean-env
.clean-env:
rm -rf $(ENV)
.PHONY: .clean-build
.clean-build:
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
.PHONY: .clean-test
.clean-test:
rm -rf .coverage
.PHONY: .clean-dist
.clean-dist:
rm -rf dist build