forked from fetchai/cosmpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
301 lines (242 loc) · 8.54 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
COSMOS_SDK_URL := https://github.com/fetchai/cosmos-sdk
COSMOS_SDK_VERSION := v0.18.0
COSMOS_SDK_DIR := build/cosmos-sdk-proto-schema
WASMD_URL := https://github.com/CosmWasm/wasmd
WASMD_VERSION := v0.24.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
OUTPUT_FOLDER := cosmpy/protos
PYCOSM_SRC_DIR := cosmpy
PYCOSM_DOCS_DIR := docs
PYCOSM_TESTS_DIR := tests
PYCOSM_EXAMPLES_DIR := examples
REQUIREMENTS_FILES := requirements.txt requirements-dev.txt
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 -fr $(OUTPUT_FOLDER)/*
python -m grpc_tools.protoc --proto_path=$(WASMD_DIR)/proto --proto_path=$(WASMD_DIR)/third_party/proto --python_out=$(OUTPUT_FOLDER) --grpc_python_out=$(OUTPUT_FOLDER) $(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=$(OUTPUT_FOLDER) --grpc_python_out=$(OUTPUT_FOLDER) $(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=$(OUTPUT_FOLDER) --grpc_python_out=$(OUTPUT_FOLDER) $(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 $(OUTPUT_FOLDER)/ -type d -exec touch {}/__init__.py \;
# restore root __init__.py as it contains code to have the proto files module available
git restore $(OUTPUT_FOLDER)/__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)
####################
### Code style
####################
.PHONY: black-check
black-check:
black --check --verbose $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --exclude $(OUTPUT_FOLDER)
.PHONY: isort-check
isort-check:
isort --check-only --verbose $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
.PHONY: flake
flake:
flake8 $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
.PHONY: vulture
vulture:
vulture $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100
####################
### Security & Safety
####################
.PHONY: bandit
bandit:
bandit -r $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) --skip B101
bandit -r $(PYCOSM_EXAMPLES_DIR) --skip B101,B105
.PHONY: safety
safety:
safety check -i 41002
####################
### Linters
####################
.PHONY: mypy
mypy:
mypy $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
.PHONY: pylint
pylint:
pylint $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
####################
### Tests
####################
.PHONY: test
test:
coverage run -m pytest $(PYCOSM_TESTS_DIR) --doctest-modules --ignore $(PYCOSM_TESTS_DIR)/vulture_whitelist.py
$(MAKE) coverage-report
.PHONY: unit-test
unit-test:
coverage run -m pytest $(PYCOSM_TESTS_DIR) --doctest-modules --ignore $(PYCOSM_TESTS_DIR)/vulture_whitelist.py -m "not integration"
.PHONY: integration-test
integration-test:
coverage run -m pytest $(PYCOSM_TESTS_DIR) --doctest-modules --ignore $(PYCOSM_TESTS_DIR)/vulture_whitelist.py -m "integration"
.PHONY: coverage-report
coverage-report:
coverage report -m
coverage html
####################
### License and copyright checks
####################
.PHONY: liccheck
liccheck:
liccheck -s strategy.ini -r requirements.txt -l PARANOID
.PHONY: copyright-check
copyright-check:
python scripts/check_copyright.py
####################
### Docs generation
####################
.PHONY: docs
docs:
mkdocs build --clean
.PHONY: docs-live
docs-live:
mkdocs serve
####################
### Clean and init commands
####################
.PHONY: clean
clean: clean-build clean-pyc clean-test
.PHONY: clean-build
clean-build:
rm -fr build/
rm -fr dist/
rm -fr .eggs/
rm -fr pip-wheel-metadata
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -fr {} +
.PHONY: clean-docs
clean-docs:
rm -fr site/
.PHONY: clean-pyc
clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
find . -name '.DS_Store' -exec rm -fr {} +
.PHONY: clean-test
clean-test:
rm -fr .tox/
rm -f .coverage
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
rm -fr coverage_report/
rm -fr .hypothesis
rm -fr .pytest_cache
rm -fr .mypy_cache/
find . -name 'log.txt' -exec rm -fr {} +
find . -name 'log.*.txt' -exec rm -fr {} +
v := $(shell pip -V | grep virtualenvs)
.PHONY: new_env
new_env: clean
if [ -z "$v" ];\
then\
pipenv --rm;\
pipenv install --python 3.9;\
echo "Enter virtual environment with all development dependencies now: 'pipenv shell'.";\
else\
echo "In a virtual environment! Exit first: 'exit'.";\
fi
.PHONY: new_env_dev
new_env_dev: clean
if [ -z "$v" ];\
then\
pipenv --rm;\
pipenv install --python 3.9 --dev --skip-lock --clear;\
echo "Enter virtual environment with all development dependencies now: 'pipenv shell'.";\
else\
echo "In a virtual environment! Exit first: 'exit'.";\
fi
####################
### Combinations
####################
.PHONY: lint
lint:
black $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --exclude $(OUTPUT_FOLDER)
isort $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
flake8 $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
vulture $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100
.PHONY: security
security:
bandit -r $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) --skip B101
bandit -r $(PYCOSM_EXAMPLES_DIR) --skip B101,B105
safety check -i 41002
.PHONY: check
check:
$(MAKE) black-check
$(MAKE) isort-check
$(MAKE) flake
$(MAKE) vulture
$(MAKE) bandit
$(MAKE) safety
$(MAKE) mypy
$(MAKE) pylint
$(MAKE) liccheck
$(MAKE) copyright-check
$(MAKE) test
Pipfile.lock: Pipfile setup.py
pipenv lock --dev
requirements.txt: Pipfile.lock
pipenv lock -r > $@
requirements-dev.txt: Pipfile.lock
pipenv lock -r --dev > $@
.PHONY: requirements
requirements: $(REQUIREMENTS_FILES)
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))