-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
242 lines (203 loc) · 7.2 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
ROOT = $(shell git rev-parse --show-toplevel)
OS = $(shell uname -s)
ARCH = $(shell uname -m | sed -e 's/i.86/i386/' -e 's/aarch64/arm64/' -e 's/amd64/x86_64/')
PKG = $(shell sed -n 's/^ *name.*=.*"\([^"]*\)".*/\1/p' pyproject.toml)
VERSION = $(shell sed -n 's/^ *version.*=.*"\([^"]*\)".*/\1/p' pyproject.toml)
DIST_DIR = $(ROOT)/dist
CACHE_DIR = $(ROOT)/.cache
VENV_DIR = $(ROOT)/.venv
BIN_DIR = $(ROOT)/bin
PROJECT_DIR = $(ROOT)/$(PKG)
MW_TMP_DIR = $(CACHE_DIR)/racoon-mw
MW_OUT_DIR = $(MW_TMP_DIR)/out
MW_FILENAME = ssl-RACOON-MW_*_$(OS)_$(ARCH).tar.gz
MW_DOWNLOADED = $(wildcard $(MW_TMP_DIR)/$(MW_FILENAME))
PROTO_SRCDIR = $(PROJECT_DIR)/proto/pb_src
PROTO_GENDIR = $(PROJECT_DIR)/proto/pb_gen
PKG_FILENAME = $(PKG)-$(VERSION)
WHEEL = $(DIST_DIR)/$(PKG_FILENAME)-py3-none-any.whl
TGZ = $(DIST_DIR)/$(PKG_FILENAME).tar.gz
TARGETS = $(WHEEL) $(TGZ)
PROTO_SRCS = $(wildcard $(PROTO_SRCDIR)/*.proto)
PROTO_PYS = $(PROTO_SRCS:$(PROTO_SRCDIR)/%.proto=$(PROTO_GENDIR)/%_pb2.py)
PROTO_STUBS = $(PROTO_SRCS:$(PROTO_SRCDIR)/%.proto=$(PROTO_GENDIR)/%_pb2.pyi)
PY_SRCS = $(ROOT)/$(PKG) $(ROOT)/cmd
PY_LOCKFILE = $(ROOT)/$(PKG)/poetry.lock
PROTOC = protoc
RACOON_MW = $(BIN_DIR)/RACOON-MW.exe
VERCHEW = $(BIN_DIR)/verchew
PROTOC_GEN_MYPY = $(VENV_DIR)/bin/protoc-gen-mypy
PROTOL = $(VENV_DIR)/bin/protol
BLACK = $(VENV_DIR)/bin/black
ISORT = $(VENV_DIR)/bin/isort
# *************************************************************************** #
.PHONY: all
all: clean build
.PHONY: build
build: doctor $(WHEEL)
$(TGZ):
@echo ""
$(error [ERROR] Please compile with `make` to cleanup and build, or use just `make build`)
$(WHEEL): $(PROJECT_DIR) $(PROTO_GENDIR)/%.pyi
@echo ""
$(info ----------------------------------------------)
@echo "Creating $(PKG)@$(VERSION) distribution..."
@poetry build -vv
$(PROTO_GENDIR)/%.pyi: $(PROTO_GENDIR)/%.py $(PROTOL)
@echo ""
$(info ----------------------------------------------)
$(info Editing stub files...)
@poetry run protol \
--in-place \
--python-out $(@D) \
$(PROTOC) --proto-path=$(PROTO_SRCDIR) $(PROTO_SRCS)
$(PROTO_GENDIR)/%.py: $(PROTO_SRCS) $(PROTOC_GEN_MYPY)
@echo ""
$(info ----------------------------------------------)
$(info Compiling protobuf files...)
@$(PROTOC) \
--proto_path=$(<D) \
--plugin=protoc-gen-mypy=$(PROTOC_GEN_MYPY) \
--python_out=$(@D) \
--mypy_out=$(@D) \
$(PROTO_SRCS)
$(PROTOL):
$(PROTOC_GEN_MYPY): $(VENV_DIR)
$(VENV_DIR): poetry.lock clean-deps $(BIN_DIR)/%
$(BIN_DIR)/%: $(MW_OUT_DIR)/%
@echo ""
$(info ----------------------------------------------)
$(info Linking RACOON-MW...)
@ln -sf $(<D)/ssl-RACOON-MW $(RACOON_MW)
$(MW_OUT_DIR)/%:
@echo ""
$(info ----------------------------------------------)
$(info Downloading RACOON-MW...)
@gh release download \
--repo Rione/ssl-RACOON-MW \
--dir $(MW_TMP_DIR) \
--pattern $(MW_FILENAME)
$(info ----------------------------------------------)
$(info Extracting RACOON-MW...)
@mkdir -p $(@D)
@tar xzvf $(wildcard $(MW_TMP_DIR)/$(MW_FILENAME)) -C $(@D)
# *************************************************************************** #
.PHONY: doctor
doctor:
@echo ""
$(info ----------------------------------------------)
$(info Checking dependencies versions for $(PKG)@$(VERSION) ...)
@$(VERCHEW) --exit-code
.PHONY: install
install:
@echo ""
$(info ----------------------------------------------)
$(info Installing ...)
@poetry install
@poetry run pre-commit install
.PHONY: run
run: doctor $(TGZ) install
@echo ""
$(info ----------------------------------------------)
@poetry run python -m $(PKG)
.PHONY: clean
clean: clean-dirs clean-deps
clean-dirs:
@echo ""
$(info ----------------------------------------------)
$(info Cleaning up...)
@rm -f $(TARGETS) $(PROTO_PYS) $(PROTO_STUBS) $(RACOON_MW) $(MW_OUT_DIR)/* $(wildcard $(MW_TMP_DIR)/$(MW_FILENAME))
@find . -name '*~' -exec rm -f {} +
@find . -name '__pycache__' -exec rm -fr {} +
.PHONY: clean-deps
clean-deps:
@echo ""
$(info ----------------------------------------------)
@poetry install --remove-untracked --no-root
# *************************************************************************** #
.PHONY: lint
lint: flake8 pylint mypy black-check isort-check
.PHONY: flake8
flake8:
@echo ""
$(info ----------------------------------------------)
@echo "Running flake8..."
@poetry run flake8 --config $(ROOT)/.flake8 --statistics --exit-zero --benchmark $(ROOT)
.PHONY: pylint
pylint:
@echo ""
$(info ----------------------------------------------)
$(info "Running pylint...")
@poetry run pylint --exit-zero --rcfile=$(ROOT)/pyproject.toml --output-format=colorized --reports=y $(PKG)
.PHONY: mypy
mypy:
@echo ""
$(info ----------------------------------------------)
$(info "Running mypy...")
@poetry run mypy --config-file=$(ROOT)/pyproject.toml --pretty $(ROOT) || true
.PHONY: black-check
black-check:
@echo ""
$(info ----------------------------------------------)
$(info "Checking code formatting with black...")
@poetry run black --verbose --check --color --config $(ROOT)/pyproject.toml $(ROOT)
.PHONY: isort-check
isort-check:
@echo ""
$(info ----------------------------------------------)
$(info "Checking code formatting with isort...")
@poetry run isort --verbose --check-only --settings-file $(ROOT)/pyproject.toml --color $(ROOT)
# *************************************************************************** #
.PHONY: format
format: black isort
.PHONY: black
black:
@echo ""
$(info ----------------------------------------------)
$(info "Formatting code with black...")
poetry run black --config $(ROOT)/pyproject.toml $(ROOT)
.PHONY: isort
isort:
@echo ""
$(info ----------------------------------------------)
$(info "Formatting code with isort...")
poetry run isort --verbose --settings-file $(ROOT)/pyproject.toml --color $(ROOT)
# *************************************************************************** #
.PHONY: help
help:
@echo "Usage: make <target>"
@echo ""
@echo " run: just run the runner script (withoud building)"
@echo " install: install dependencies"
@echo " build: build this project"
@echo " clean: clean this project"
@echo " lint: run the all linters"
@echo " format: run the all formatters"
@echo " help: show more verbose help"
.PHONY: help-long
help-long:
@echo "Usage: make <target>"
@echo ""
@echo "[help]"
@echo " help: show help"
@echo " help-long: show more verbose help (this one)"
@echo ""
@echo "[main]"
@echo " run: run the runner script (withoud building)"
@echo " install: install dependencies"
@echo " build: build this project"
@echo ""
@echo "[cleanup]"
@echo " clean: clean this project"
@echo " clean-deps: auto-remove unlisted packages"
@echo " clean-dirs: remove chaches and compiled files"
@echo ""
@echo "[lint]"
@echo " lint: run the all linters"
@echo " pylint: lint code with pylint"
@echo " flake8: lint code with flake8"
@echo ""
@echo "[format]"
@echo " format: run the all formatters"
@echo " black: format code with black"
@echo " isort: format code with isort"