-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
183 lines (147 loc) · 5.11 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
# This helps with creating local virtual environments, requirements,
# syntax checking, running tests, coverage and uploading packages to PyPI.
# Homepage at https://github.com/jidn/python-Makefile
#
# This also works with Travis CI
#
# PACKAGE = Source code directory or leave empty
PACKAGE = src
TESTDIR = tests
PROJECT :=
VENV = venv
# Override by putting on commandline: python=python3.8
python = python
PEP8_IGNORE := E501,E123
PEP257_IGNORE := D104,D203
##############################################################################
ifdef TRAVIS
VENV = $(VIRTUAL_ENV)
endif
# System paths
BIN := $(VENV)/bin
OPEN := xdg-open
# virtualenv executables
PIP := $(BIN)/pip
TOX := $(BIN)/tox
PYTHON := $(BIN)/$(python)
FLAKE8 := $(BIN)/flake8
PEP257 := $(BIN)/pydocstyle
# Project settings
PKGDIR := $(or $(PACKAGE), ./)
SETUP_PY := $(wildcard setup.py)
SOURCES := $(wildcard *.py)
EGG_INFO := $(subst -,_,$(PROJECT)).egg-info
### Main Targets #############################################################
.PHONY: all env ci help
all: check test
# Target for Travis
ci: test
venv: $(PIP)
$(PIP):
# Create the virtual enviornment
$(info "Environment is $(VENV)")
python -m venv $(VENV)
$(PIP) install --upgrade pip
@# pip install the requirements/base.txt
@test -f requirements/base.txt && $(PIP) install -qr requirements/base.txt || true
@# With pyproject.toml, pip install this directory as editable
@test -f pyproject.toml && $(PIP) install -qe . || true
@# public service announcement
@echo "Remember to activate the virtual environment."
@echo " . venv/bin/activate"
pip: $(PIP)
pip install --upgrade -r requirements/$(lastword $(MAKECMDGOALS))
help:
@echo "venv Create virtual environment and install requirements"
@echo " python=PYTHON_EXE interpreter to use, default=python"
@echo "pip FILE Install requirements/FILE"
@echo "check Run style checks"
@echo "test $(TESTDIR)"/
@echo "coverage Get coverage information, optional 'args' like test"
@echo "tox Test against multiple versions of python"
@echo "upload Upload package to PyPI"
@echo "clean clean-all Clean up and clean up removing virtualenv"
### Static Analysis & Travis CI ##############################################
.PHONY: check flake8 pep257
check: flake8 pep257
$(FLAKE8): $(PIP)
$(PIP) install --upgrade flake8 pydocstyle
flake8: $(FLAKE8)
$(FLAKE8) $(or $(PACKAGE), $(SOURCES)) $(TESTDIR) --ignore=$(PEP8_IGNORE)
pep257: $(FLAKE8)
$(PEP257) $(or $(PACKAGE), $(SOURCES)) $(ARGS) --ignore=$(PEP257_IGNORE)
### Testing ##################################################################
.PHONY: test tox
test: $(VENV)/bin/py.test
$(VENV)/bin/py.test
$(VENV)/bin/py.test: $(PIP)
$(PIP) install -qr requirements/test.txt
.coveragerc:
ifeq ($(PKGDIR),./)
ifeq (,$(wildcard $(.coveragerc)))
# If PKGDIR is root directory, ie code is not in its own directory
# then you should use a .coveragerc file to remove the VENV directory
# from the coverage search. I'll auto generate one for you.
$(info Rerun make to discover autocreated .coveragerc)
@echo -e "[run]\nomit=$(VENV)/*" > .coveragerc; cat .coveragerc
@exit 1
endif
endif
coverage:
coverage run -m pytest
coverage report
tox: $(TOX)
$(TOX)
$(TOX): $(PIP)
$(PIP) install tox
### Cleanup ##################################################################
.PHONY: clean clean-env clean-all clean-build clean-test clean-dist
clean: clean-dist clean-test clean-build
clean-env: clean
-@rm -rf $(VENV)
-@rm -rf .tox
clean-all: clean clean-env
clean-build:
@find $(PKGDIR) -name '*.pyc' -delete
@find $(PKGDIR) -name '__pycache__' -delete
@find $(TESTDIR) -name '*.pyc' -delete 2>/dev/null || true
@find $(TESTDIR) -name '__pycache__' -delete 2>/dev/null || true
-@rm -rf $(EGG_INFO)
-@rm -rf __pycache__
clean-test:
-@rm -rf .coverage
clean-dist:
-@rm -rf dist build
### Release ##################################################################
# For more information on creating packages for PyPI see the writeup at
# http://peterdowns.com/posts/first-time-with-pypi.html
.PHONY: authors register dist upload .git-no-changes
authors:
echo "Authors\n=======\n\nA huge thanks to all of our contributors:\n\n" > AUTHORS.md
git log --raw | grep "^Author: " | cut -d ' ' -f2- | cut -d '<' -f1 | sed 's/^/- /' | sort | uniq >> AUTHORS.md
register:
$(PYTHON) setup.py register -r pypi
dist: test
$(PYTHON) setup.py sdist
$(PYTHON) setup.py bdist_wheel
upload: .git-no-changes register
$(PYTHON) setup.py sdist upload -r pypi
$(PYTHON) setup.py bdist_wheel upload -r pypi
.git-no-changes:
@if git diff --name-only --exit-code; \
then \
echo Git working copy is clean...; \
else \
echo ERROR: Git working copy is dirty!; \
echo Commit your changes and try again.; \
exit -1; \
fi;
### System Installation ######################################################
.PHONY: develop install download
# Is this section really needed?
develop:
$(PYTHON) setup.py develop
install:
$(PYTHON) setup.py install
download:
$(PIP) install $(PROJECT)