|
| 1 | +# Project settings |
| 2 | +PROJECT := Flask-API |
| 3 | +PACKAGE := flask_api |
| 4 | +REPOSITORY := flask-api/flask-api |
| 5 | + |
| 6 | +# Project paths |
| 7 | +PACKAGES := $(PACKAGE) tests |
| 8 | +CONFIG := $(wildcard *.py) |
| 9 | +MODULES := $(wildcard $(PACKAGE)/*.py) |
| 10 | + |
| 11 | +# Python settings |
| 12 | +PYTHON_MAJOR ?= 2 |
| 13 | +PYTHON_MINOR ?= 7 |
| 14 | + |
| 15 | +# System paths |
| 16 | +PLATFORM := $(shell python -c 'import sys; print(sys.platform)') |
| 17 | +ifneq ($(findstring win32, $(PLATFORM)), ) |
| 18 | + WINDOWS := true |
| 19 | + SYS_PYTHON_DIR := C:\\Python$(PYTHON_MAJOR)$(PYTHON_MINOR) |
| 20 | + SYS_PYTHON := $(SYS_PYTHON_DIR)\\python.exe |
| 21 | + # https://bugs.launchpad.net/virtualenv/+bug/449537 |
| 22 | + export TCL_LIBRARY=$(SYS_PYTHON_DIR)\\tcl\\tcl8.5 |
| 23 | +else |
| 24 | + ifneq ($(findstring darwin, $(PLATFORM)), ) |
| 25 | + MAC := true |
| 26 | + else |
| 27 | + LINUX := true |
| 28 | + endif |
| 29 | + SYS_PYTHON := python$(PYTHON_MAJOR) |
| 30 | + ifdef PYTHON_MINOR |
| 31 | + SYS_PYTHON := $(SYS_PYTHON).$(PYTHON_MINOR) |
| 32 | + endif |
| 33 | +endif |
| 34 | + |
| 35 | +# Virtual environment paths |
| 36 | +ENV := .venv |
| 37 | +ifneq ($(findstring win32, $(PLATFORM)), ) |
| 38 | + BIN := $(ENV)/Scripts |
| 39 | + ACTIVATE := $(BIN)/activate.bat |
| 40 | + OPEN := cmd /c start |
| 41 | + PYTHON := $(BIN)/python.exe |
| 42 | + PIP := $(BIN)/pip.exe |
| 43 | +else |
| 44 | + BIN := $(ENV)/bin |
| 45 | + ACTIVATE := . $(BIN)/activate |
| 46 | + ifneq ($(findstring cygwin, $(PLATFORM)), ) |
| 47 | + OPEN := cygstart |
| 48 | + else |
| 49 | + OPEN := open |
| 50 | + endif |
| 51 | + PYTHON := $(BIN)/python |
| 52 | + PIP := $(BIN)/pip |
| 53 | +endif |
| 54 | + |
| 55 | +# MAIN TASKS ################################################################### |
| 56 | + |
| 57 | +SNIFFER := pipenv run sniffer |
| 58 | + |
1 | 59 | .PHONY: all
|
2 | 60 | all: install
|
3 | 61 |
|
| 62 | +.PHONY: ci |
| 63 | +ci: check test ## Run all tasks that determine CI status |
| 64 | + |
| 65 | +.PHONY: watch |
| 66 | +watch: install .clean-test ## Continuously run all CI tasks when files chanage |
| 67 | + $(SNIFFER) |
| 68 | + |
| 69 | +.PHONY: run ## Start the program |
| 70 | +run: install |
| 71 | + $(PYTHON) $(PACKAGE)/__main__.py |
| 72 | + |
4 | 73 | # PROJECT DEPENDENCIES #########################################################
|
5 | 74 |
|
6 | 75 | export PIPENV_SHELL_COMPAT=true
|
7 | 76 | export PIPENV_VENV_IN_PROJECT=true
|
| 77 | +export PIPENV_IGNORE_VIRTUALENVS=true |
8 | 78 |
|
9 |
| -ENV := .venv |
10 | 79 | DEPENDENCIES := $(ENV)/.installed
|
11 |
| -PIP := $(ENV)/bin/pip |
| 80 | +METADATA := *.egg-info |
12 | 81 |
|
13 | 82 | .PHONY: install
|
14 |
| -install: $(DEPENDENCIES) |
| 83 | +install: $(DEPENDENCIES) $(METADATA) |
15 | 84 |
|
16 | 85 | $(DEPENDENCIES): $(PIP) Pipfile*
|
17 |
| - pipenv install --dev --ignore-hashes |
| 86 | + pipenv install --dev |
| 87 | +ifdef WINDOWS |
| 88 | + @ echo "Manually install pywin32: https://sourceforge.net/projects/pywin32/files/pywin32" |
| 89 | +else ifdef MAC |
| 90 | + $(PIP) install pync MacFSEvents |
| 91 | +else ifdef LINUX |
| 92 | + $(PIP) install pyinotify |
| 93 | +endif |
| 94 | + @ touch $@ |
| 95 | + |
| 96 | +$(METADATA): $(PYTHON) setup.py |
| 97 | + $(PYTHON) setup.py develop |
18 | 98 | @ touch $@
|
19 | 99 |
|
20 |
| -$(PIP): |
21 |
| - pipenv --python=python3.6 |
| 100 | +$(PYTHON) $(PIP): |
| 101 | + pipenv --python=$(SYS_PYTHON) |
| 102 | + pipenv run pip --version |
| 103 | + |
| 104 | +# CHECKS ####################################################################### |
| 105 | + |
| 106 | +FLAKE8 := pipenv run flake8 |
| 107 | + |
| 108 | +.PHONY: check |
| 109 | +check: flake8 ## Run linters and static analysis |
22 | 110 |
|
23 |
| -# VALIDATION TARGETS ########################################################### |
| 111 | +.PHONY: flake8 |
| 112 | +flake8: install |
| 113 | + $(FLAKE8) flask_api --ignore=E128,E501 --exclude=__init__.py |
| 114 | + |
| 115 | +# TESTS ######################################################################## |
| 116 | + |
| 117 | +NOSE := pipenv run nosetests |
| 118 | +COVERAGE := pipenv run coverage |
| 119 | +COVERAGE_SPACE := pipenv run coverage.space |
| 120 | + |
| 121 | +RANDOM_SEED ?= $(shell date +%s) |
| 122 | + |
| 123 | +NOSE_OPTIONS := --with-doctest |
| 124 | +ifndef DISABLE_COVERAGE |
| 125 | +NOSE_OPTIONS += --with-coverage --cover-package=$(PACKAGE) --cover-erase --cover-html --cover-html-dir=htmlcov --cover-branches |
| 126 | +endif |
24 | 127 |
|
25 | 128 | .PHONY: test
|
26 |
| -test: install ## Run tests and linters |
27 |
| - pipenv run nosetests flask_api |
28 |
| - pipenv run flake8 flask_api --ignore=E128,E501 --exclude=__init__.py |
| 129 | +test: install ## Run unit and integration tests |
| 130 | + $(NOSE) $(PACKAGE) $(NOSE_OPTIONS) |
| 131 | + $(COVERAGE_SPACE) $(REPOSITORY) overall |
| 132 | + |
| 133 | +.PHONY: read-coverage |
| 134 | +read-coverage: |
| 135 | + $(OPEN) coverage/index.html |
| 136 | + |
| 137 | +# DOCUMENTATION ################################################################ |
| 138 | + |
| 139 | +MKDOCS := pipenv run mkdocs |
| 140 | + |
| 141 | +MKDOCS_INDEX := site/index.html |
| 142 | + |
| 143 | +.PHONY: doc |
| 144 | +doc: mkdocs ## Generate documentation |
| 145 | + |
| 146 | +.PHONY: mkdocs |
| 147 | +mkdocs: install $(MKDOCS_INDEX) |
| 148 | +$(MKDOCS_INDEX): mkdocs.yml docs/*.md |
| 149 | + $(MKDOCS) build --clean --strict |
| 150 | + |
| 151 | +.PHONY: mkdocs-live |
| 152 | +mkdocs-live: mkdocs |
| 153 | + eval "sleep 3; open http://127.0.0.1:8000" & |
| 154 | + $(MKDOCS) serve |
| 155 | + |
| 156 | +# RELEASE ###################################################################### |
| 157 | + |
| 158 | +TWINE := pipenv run twine |
| 159 | + |
| 160 | +.PHONY: register |
| 161 | +register: dist ## Register the project on PyPI |
| 162 | + @ echo NOTE: your project must be registered manually |
| 163 | + @ echo https://github.com/pypa/python-packaging-user-guide/issues/263 |
| 164 | + # TODO: switch to twine when the above issue is resolved |
| 165 | + # $(TWINE) register dist/*.whl |
| 166 | + |
| 167 | +.PHONY: upload |
| 168 | +upload: .git-no-changes register ## Upload the current version to PyPI |
| 169 | + $(TWINE) upload dist/*.* |
| 170 | + $(OPEN) https://pypi.python.org/pypi/$(PROJECT) |
| 171 | + |
| 172 | +.PHONY: .git-no-changes |
| 173 | +.git-no-changes: |
| 174 | + @ if git diff --name-only --exit-code; \ |
| 175 | + then \ |
| 176 | + echo Git working copy is clean...; \ |
| 177 | + else \ |
| 178 | + echo ERROR: Git working copy is dirty!; \ |
| 179 | + echo Commit your changes and try again.; \ |
| 180 | + exit -1; \ |
| 181 | + fi; |
29 | 182 |
|
30 | 183 | # CLEANUP ######################################################################
|
31 | 184 |
|
32 | 185 | .PHONY: clean
|
33 |
| -clean: |
| 186 | +clean: .clean-dist .clean-test .clean-doc .clean-build ## Delete all generated and temporary files |
| 187 | + |
| 188 | +.PHONY: clean-all |
| 189 | +clean-all: clean .clean-env .clean-workspace |
| 190 | + |
| 191 | +.PHONY: .clean-build |
| 192 | +.clean-build: |
| 193 | + find $(PACKAGES) -name '*.pyc' -delete |
| 194 | + find $(PACKAGES) -name '__pycache__' -delete |
| 195 | + rm -rf *.egg-info |
| 196 | + |
| 197 | +.PHONY: .clean-doc |
| 198 | +.clean-doc: |
| 199 | + rm -rf README.rst docs/apidocs *.html docs/*.png site |
| 200 | + |
| 201 | +.PHONY: .clean-test |
| 202 | +.clean-test: |
| 203 | + rm -rf .cache .pytest .coverage htmlcov xmlreport |
| 204 | + |
| 205 | +.PHONY: .clean-dist |
| 206 | +.clean-dist: |
| 207 | + rm -rf *.spec dist build |
| 208 | + |
| 209 | +.PHONY: .clean-env |
| 210 | +.clean-env: clean |
34 | 211 | rm -rf $(ENV)
|
| 212 | + |
| 213 | +.PHONY: .clean-workspace |
| 214 | +.clean-workspace: |
| 215 | + rm -rf *.sublime-workspace |
| 216 | + |
| 217 | +# HELP ######################################################################### |
| 218 | + |
| 219 | +.PHONY: help |
| 220 | +help: all |
| 221 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
| 222 | + |
| 223 | +.DEFAULT_GOAL := help |
0 commit comments