-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
147 lines (125 loc) · 3.64 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
VIRTUAL_ENV_PATH=venv
SKIP_VENV="${NO_VENV}"
SHELL := /bin/bash
PYPI_API_KEY :=
PYPI_REPOSITORY_URL :=
ALPHA_VERSION :=
SRC_ROOT := ./src
FORMAT_PATH := $(SRC_ROOT)
.DEFAULT_GOAL := pre_commit
pre_commit: copyright format lint
setup: venv deps
copyright:
@( \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
echo "Applying copyright..."; \
for p in $(FORMAT_PATH); do \
licenseheaders -t ./development/copyright.tmpl -E ".py" -cy -d $$p; \
done; \
echo "Done: copyright"; \
)
flake8:
@( \
set -e; \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
echo "Running Flake8 checks..."; \
flake8 $(SRC_ROOT) --count --statistics; \
\
echo "DONE: Flake8"; \
)
mypy:
@( \
set -e; \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
echo "Running MyPy checks..."; \
mypy --show-error-codes $(SRC_ROOT)/tapen; \
mypy --show-error-codes $(SRC_ROOT)/ptouch_py; \
\
echo "DONE: MyPy"; \
)
format:
@( \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
echo "Running Black code formatter..."; \
black $(SRC_ROOT)/tapen $(SRC_ROOT)/ptouch_py; \
\
echo "DONE: Black"; \
)
check-format:
@( \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
echo "Running Black format check..."; \
black --check $(SRC_ROOT)/tapen $(SRC_ROOT)/ptouch_py; \
\
echo "DONE: Black format check"; \
)
lint: flake8 mypy check-format
build: copyright format lint clean
@( \
set -e; \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
echo "Building wheel package..."; \
poetry build; \
echo "DONE: wheel package"; \
)
package:
@( \
echo "Building packages"; \
set -e; \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
poetry build; \
echo "DONE: Building packages"; \
)
single-binary:
@( \
set -e; \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
echo "Building single binary"; \
bash -c "pyinstaller tapen.spec"; \
echo "DONE: wheel package"; \
)
clean:
@(rm -rf src/build dist/* *.egg-info src/*.egg-info .pytest_cache)
publish:
@( \
set -e; \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
if [ ! -z $(PYPI_API_KEY) ]; then export TWINE_USERNAME="__token__"; export TWINE_PASSWORD="$(PYPI_API_KEY)"; fi; \
if [ ! -z $(PYPI_REPOSITORY_URL) ]; then export TWINE_REPOSITORY_URL="$(PYPI_REPOSITORY_URL)"; fi; \
echo "Uploading to PyPi"; \
twine upload -r pypi dist/*; \
echo "DONE: Publish"; \
)
set-version:
@( \
if [ -z $(VERSION) ]; then echo "Missing VERSION argument"; exit 1; fi; \
echo '__version__ = "$(VERSION)"' > $(SRC_ROOT)/__version__.py; \
echo "Version updated: $(VERSION)"; \
)
deps:
@( \
set -e; \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
poetry install --all-extras --no-root; \
)
deps-update:
@( \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
poetry lock; \
)
deps-lock:
@( \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
poetry lock --no-update \
)
deps-tree:
@( \
if [ -z $(SKIP_VENV) ]; then source $(VIRTUAL_ENV_PATH)/bin/activate; fi; \
poetry show --tree; \
)
.PHONY: venv
venv:
@( \
python3 -m venv $(VIRTUAL_ENV_PATH); \
source $(VIRTUAL_ENV_PATH)/bin/activate; \
)