-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
310 lines (251 loc) · 9.19 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
########################################
### Initialise dev environment
########################################
# Create a new poetry virtual environment with all the necessary dependencies installed.
# Once finished, `poetry shell` to enter the virtual environment
v := $(shell pip -V | grep virtualenvs)
.PHONY: new_env
new_env_dev: clean
if [ -z "$v" ];\
then\
poetry install --with main,dev,test,docs --sync;\
echo "Enter virtual environment with all development dependencies now: 'poetry shell'.";\
else\
echo "In a virtual environment! Exit first: 'exit'.";\
fi
########################################
### Useful linting command
########################################
# Automatically runs black and isort to format the code, and runs flake8 and vulture checks
.PHONY: lint
lint: black isort flake8 vulture
########################################
### Tests
########################################
# Run all tests
.PHONY: test
test:
coverage run -m pytest $(COSMPY_TESTS_DIR) --doctest-modules --ignore $(COSMPY_TESTS_DIR)/vulture_whitelist.py
$(MAKE) coverage-report
# Run all unit tests
.PHONY: unit-test
unit-test:
coverage run -m pytest $(COSMPY_TESTS_DIR) --doctest-modules --ignore $(COSMPY_TESTS_DIR)/vulture_whitelist.py -m "not integration"
# Run all integration tests
.PHONY: integration-test
integration-test:
coverage run -m pytest $(COSMPY_TESTS_DIR) --doctest-modules --ignore $(COSMPY_TESTS_DIR)/vulture_whitelist.py -m "integration"
# Produce the coverage report. Can see a report summary on the terminal.
# Detailed report on all modules are placed under /coverage-report
.PHONY: coverage-report
coverage-report:
coverage report -m
coverage html
########################################
### Automatic Styling
########################################
# Automatically formats the code
.PHONY: black
black:
black $(PYTHON_CODE_DIRS) --exclude $(COSMPY_PROTOS_DIR)
# Automatically sorts the imports
.PHONY: isort
isort:
isort $(PYTHON_CODE_DIRS)
########################################
### Code style checks
########################################
# Runs the black format checker
.PHONY: black-check
black-check:
black --check --verbose $(PYTHON_CODE_DIRS) --exclude $(COSMPY_PROTOS_DIR)
# Runs the isort format checker
.PHONY: isort-check
isort-check:
isort --check-only --verbose $(PYTHON_CODE_DIRS)
# Runs flake8 checker
.PHONY: flake8
flake:
flake8 $(PYTHON_CODE_DIRS)
# Runs vulture checker (checks for unused code)
.PHONY: vulture
vulture:
vulture $(PYTHON_CODE_DIRS) --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100
########################################
### Security & safety checks
########################################
# Checks the security of the code
.PHONY: bandit
bandit:
bandit -r $(COSMPY_SRC_DIR) $(COSMPY_TESTS_DIR) --skip B101
bandit -r $(COSMPY_EXAMPLES_DIR) --skip B101,B105
# Checks the security of the code
.PHONY: safety
safety:
safety check -i 41002
########################################
### Linters
########################################
# Runs the mypy linter
.PHONY: mypy
mypy:
mypy $(PYTHON_CODE_DIRS)
# Runs the pylint linter
.PHONY: pylint
pylint:
pylint $(PYTHON_CODE_DIRS)
########################################
### License and copyright checks
########################################
# Check licenses
.PHONY: liccheck
liccheck:
poetry export > tmp-requirements.txt
liccheck -s strategy.ini -r tmp-requirements.txt -l PARANOID
rm -frv tmp-requirements.txt
# Check copyrights
.PHONY: copyright-check
copyright-check:
python scripts/check_copyright.py
########################################
### Docs
########################################
# Build documentation
.PHONY: docs
docs:
mkdocs build --clean
# Live documentation server
.PHONY: docs-live
docs-live:
mkdocs serve
# Generate API documentation (ensure you add the new pages created into /mkdocs.yml --> nav)
.PHONY: generate-api-docs
generate-api-docs:
python scripts/generate_api_docs.py
########################################
### Update Poetry Lock
########################################
# Updates the poetry lock
poetry.lock: pyproject.toml
poetry lock
########################################
### Clear the caches and temporary files
########################################
# clean the caches and temporary files and directories
.PHONY: clean
clean: clean-build clean-pyc clean-test clean-docs
.PHONY: clean-build
clean-build:
rm -frv build/
rm -frv dist/
rm -frv .eggs/
rm -frv pip-wheel-metadata
find . -name '*.egg-info' -exec rm -frv {} +
find . -name '*.egg' -exec rm -frv {} +
.PHONY: clean-docs
clean-docs:
rm -frv site/
.PHONY: clean-pyc
clean-pyc:
find . -name '*.pyc' -exec rm -fv {} +
find . -name '*.pyo' -exec rm -fv {} +
find . -name '*~' -exec rm -fv {} +
find . -name '__pycache__' -exec rm -frv {} +
find . -name '.DS_Store' -exec rm -frv {} +
.PHONY: clean-test
clean-test:
rm -frv .tox/
rm -frv .coverage
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -frv "{}" \;
rm -frv coverage_report/
rm -frv .hypothesis
rm -frv .pytest_cache
rm -frv .mypy_cache/
find . -name 'log.txt' -exec rm -frv {} +
find . -name 'log.*.txt' -exec rm -frv {} +
########################################
### Generate protos and grpc files
########################################
# Constants
COSMOS_SDK_URL := https://github.com/cosmos/cosmos-sdk
COSMOS_SDK_VERSION := v0.46.5
COSMOS_SDK_DIR := build/cosmos-sdk-proto-schema
WASMD_URL := https://github.com/CosmWasm/wasmd
WASMD_VERSION := v0.27.0
WASMD_DIR := build/wasm-proto-shema
IBCGO_URL := https://github.com/cosmos/ibc-go
IBCGO_VERSION := v2.2.0
IBCGO_DIR := build/ibcgo-proto-schema
COSMPY_PROTOS_DIR := cosmpy/protos
COSMPY_SRC_DIR := cosmpy
COSMPY_TESTS_DIR := tests
COSMPY_EXAMPLES_DIR := examples
PYTHON_CODE_DIRS := $(COSMPY_SRC_DIR) $(COSMPY_TESTS_DIR) $(COSMPY_EXAMPLES_DIR)
ifeq ($(OS),Windows_NT)
$(error "Please use the WSL (Windows Subsystem for Linux) on Windows platform.")
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OPEN_CMD := xdg-open
endif
ifeq ($(UNAME_S),Darwin)
OPEN_CMD := open
endif
endif
define unique
$(eval seen :=)
$(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_)))
${seen}
endef
unique = $(if $1,$(firstword $1) $(call unique,$(filter-out $(firstword $1),$1)))
proto: fetch_proto_schema_source generate_proto_types generate_init_py_files
generate_proto_types: $(COSMOS_SDK_DIR) $(WASMD_DIR) $(IBCGO_DIR)
rm -frv $(COSMPY_PROTOS_DIR)/*
python -m grpc_tools.protoc --proto_path=$(WASMD_DIR)/proto --proto_path=$(WASMD_DIR)/third_party/proto --python_out=$(COSMPY_PROTOS_DIR) --grpc_python_out=$(COSMPY_PROTOS_DIR) $(shell find $(WASMD_DIR) \( -path */proto/* -or -path */third_party/proto/* \) -type f -name *.proto)
python -m grpc_tools.protoc --proto_path=$(IBCGO_DIR)/proto --proto_path=$(IBCGO_DIR)/third_party/proto --python_out=$(COSMPY_PROTOS_DIR) --grpc_python_out=$(COSMPY_PROTOS_DIR) $(shell find $(IBCGO_DIR) \( -path */proto/* -or -path */third_party/proto/* \) -type f -name *.proto)
# ensure cosmos-sdk is last as previous modules may have duplicated proto models which are now outdated
python -m grpc_tools.protoc --proto_path=$(COSMOS_SDK_DIR)/proto --proto_path=$(COSMOS_SDK_DIR)/third_party/proto --python_out=$(COSMPY_PROTOS_DIR) --grpc_python_out=$(COSMPY_PROTOS_DIR) $(shell find $(COSMOS_SDK_DIR) \( -path */proto/* -or -path */third_party/proto/* \) -type f -name *.proto)
fetch_proto_schema_source: $(COSMOS_SDK_DIR) $(WASMD_DIR) $(IBCGO_DIR)
.PHONY: generate_init_py_files
generate_init_py_files: generate_proto_types
find $(COSMPY_PROTOS_DIR)/ -type d -exec touch {}/__init__.py \;
# restore root __init__.py as it contains code to have the proto files module available
git restore $(COSMPY_PROTOS_DIR)/__init__.py
$(SOURCE): $(COSMOS_SDK_DIR)
$(GENERATED): $(SOURCE)
$(COMPILE_PROTOBUFS_COMMAND)
$(INIT_PY_FILES_TO_CREATE): $(GENERATED_DIRS)
touch $(INIT_PY_FILES_TO_CREATE)
$(GENERATED_DIRS): $(COSMOS_SDK_DIR) $(WASMD_DIR) $(IBCGO_DIR)
$(COSMOS_SDK_DIR): Makefile
rm -rfv $(COSMOS_SDK_DIR)
git clone --branch $(COSMOS_SDK_VERSION) --depth 1 --quiet --no-checkout --filter=blob:none $(COSMOS_SDK_URL) $(COSMOS_SDK_DIR)
cd $(COSMOS_SDK_DIR) && git checkout $(COSMOS_SDK_VERSION) -- $(COSMOS_PROTO_RELATIVE_DIRS)
$(WASMD_DIR): Makefile
rm -rfv $(WASMD_DIR)
git clone --branch $(WASMD_VERSION) --depth 1 --quiet --no-checkout --filter=blob:none $(WASMD_URL) $(WASMD_DIR)
cd $(WASMD_DIR) && git checkout $(WASMD_VERSION) -- $(WASMD_PROTO_RELATIVE_DIRS)
$(IBCGO_DIR): Makefile
rm -rfv $(IBCGO_DIR)
git clone --branch $(IBCGO_VERSION) --depth 1 --quiet --no-checkout --filter=blob:none $(IBCGO_URL) $(IBCGO_DIR)
cd $(IBCGO_DIR) && git checkout $(IBCGO_VERSION) -- $(IBCGO_PROTO_RELATIVE_DIRS)
debug:
$(info SOURCES_REGEX_TO_EXCLUDE: $(SOURCES_REGEX_TO_EXCLUDE))
$(info )
$(info GENERATED_DIRS: $(GENERATED_DIRS))
$(info )
$(info INIT_PY_FILES_TO_CREATE: $(INIT_PY_FILES_TO_CREATE))
$(info )
$(info SOURCE: $(SOURCE))
$(info )
$(info RELATIVE_SOURCE: $(RELATIVE_SOURCE))
$(info )
$(info GENERATED: $(GENERATED))
$(info )
$(info UNROOTED_SOURCE: $(UNROOTED_SOURCE))
$(info )
$(info PROTO_ROOT_DIRS: $(PROTO_ROOT_DIRS))
$(info )
$(info FIND_CMD: $(FIND_CMD))
$(info )
$(info COMPILE_PROTOBUFS_COMMAND: $(COMPILE_PROTOBUFS_COMMAND))