-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
150 lines (119 loc) · 3.57 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
# This Makefile assumes it's being run someplace with pip available
PROJ=$(shell grep ^name pyproject.toml | cut -d\" -f2)
VERSION=$(shell grep ^version pyproject.toml | cut -d\" -f2)
.PHONY: default
default::
@echo "dev - set up the dev virtualenv"
@echo "wheel|$(PROJ) - build the $(PROJ) python package"
@echo "docs - build the docs into docs/_build"
@echo "pylint - run a linter on the codebase"
@echo "mypy - run a typechecker on the codebase"
@echo "test = run all tests in dev machine python"
@echo "clean - remove all build artifacts"
@echo "git-release - tag a release and push it to github"
@echo "pypi-release - push a release to pypi"
@echo "docs-release - build the docs and release to github pages"
PYTEST_ARGS = $(PYTEST_EXTRA)
DEV_REQS=dev-requirements.txt
DEV_ENV=$(VIRTUAL_ENV)/bin/pytest
PIP_VENDORED_FLAGS=$(if $(PIP_VENDORED_DIR),-f $(PIP_VENDORED_DIR),)
$(DEV_REQS): pyproject.toml
pip-compile -q --resolver=backtracking --extra=dev,all --output-file=$@ $<
$(DEV_ENV): $(DEV_REQS)
@if [ -z "$$VIRTUAL_ENV" ] ; then \
echo "You should be in a virtualenv or other isolated environment before running this."; \
exit 1; \
fi
pip install pip-tools
pip-sync $(DEV_REQS)
pip install -e .[all]
.PHONY: dev
dev: $(DEV_ENV)
wheel:
python -m build
raw-mypy raw-pylint raw-test raw-coverage: export PYTHONWARNINGS=ignore,default:::$(PROJ)
CODECOV_OUTPUT=--cov-report term
pylint: $(DEV_ENV)
pytest $(PROJ) \
--pylint --pylint-rcfile=.pylintrc \
--pylint-error-types=EF \
-m pylint \
--cache-clear
.coverage:
@echo "You must run tests first!"
exit 1
coverage-html.zip: .coverage
coverage html -d htmlconv
cd htmlconv && zip -r ../$@ .
coverage.xml: .coverage
coverage xml
test: $(DEV_ENV)
pytest tests $(PYTEST_ARGS) -l
testf: PYTEST_EXTRA=--log-cli-level=DEBUG -lx --ff
testf: test
.PHONY: mypy
mypy:
mypy --non-interactive --install-types $(PROJ)
#pytest --mypy -m mypy $(PROJ)
mypy --check-untyped-defs $(PROJ)
.PHONY: coverage
coverage:
pytest --cov=$(PROJ) $(CODECOV_OUTPUT) tests $(PYTEST_ARGS)
.PHONY: not-dirty
not-dirty:
@if [ `git status --short | wc -l` != 0 ]; then\
echo "Uncommited code. Aborting." ;\
exit 1;\
fi
#SIGN=--sign
SIGN=
.PHONY: git-release
git-release: wheel not-dirty
@if [ `git rev-parse --abbrev-ref HEAD` != main ]; then \
echo "You can only do a release from the main branch.";\
exit 1;\
fi
@if git tag | grep -q ^$(VERSION) ; then \
echo "Already released this version.";\
echo "Update the version number and try again.";\
exit 1;\
fi
git push &&\
git tag $(SIGN) $(VERSION) -m "Release v$(VERSION)" &&\
git push --tags &&\
git checkout release &&\
git merge $(VERSION) &&\
git push && git checkout main
@echo "Released! Note you're now on the 'main' branch."
.PHONY: pypi-release
pypi-release: wheel
python -m build
twine upload dist/$(PROJ)-$(VERSION)*
.PHONY: docs
docs:
$(MAKE) -C docs html
docs-release: docs
@if [ `git rev-parse --abbrev-ref HEAD` != main ]; then \
echo "You can only do a release from the main branch.";\
exit 1;\
fi
@DOCTAR=docs-$(VERSION).tgz &&\
cd docs/_build &&\
tar czf ../../$$DOCTAR html &&\
cd ../.. &&\
git checkout gh-pages &&\
rm -rf docs &&\
tar xzf $$DOCTAR &&\
rm $$DOCTAR &&\
mv html docs &&\
touch docs/.nojekyll &&\
git add -A docs &&\
git commit -m "release docs $(VERSION)" &&\
git push && git checkout main
@echo "Docs released!"
.PHONY: clean
clean:
rm -rf build dist *.egg-info shippable *.whl $(DEV_ENV)
find . -name __pycache__ | xargs rm -rf
find . -name \*.pyc | xargs rm -f
-include Makefile.proj