-
Notifications
You must be signed in to change notification settings - Fork 63
/
Makefile
350 lines (289 loc) · 11.6 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
AEA_SRC_DIR := aea
BENCHMARK_DIR := benchmark
EXAMPLES_DIR := examples
LIBS_DIR := libs
PACKAGES_DIR := packages
PLUGINS_DIR := plugins
SCRIPTS_DIR := scripts
AEA_TESTS_DIR := tests
AEA_CORE_TESTS_DIRS := tests/test_aea tests/test_aea_extra ./tests/test_docs
EXAMPLES_TESTS_DIRS := tests/test_examples
PACKAGES_TESTS_DIRS := packages/fetchai/protocols packages/fetchai/connections packages/fetchai/skills ./tests/test_packages ./tests/test_packages_for_aea_tests ./tests/test_aea_core_packages
DOCS_TESTS_DIR := tests/test_docs
CONNECTIONS_DIR := packages/fetchai/connections
CONTRACTS_DIR := packages/fetchai/contracts
PROTOCOLS_DIR := packages/fetchai/protocols
SKILLS_DIR := packages/fetchai/skills
PLUGIN_FETCHAI_SRC := plugins/aea-ledger-fetchai/aea_ledger_fetchai
PLUGIN_ETHEREUM_SRC := plugins/aea-ledger-ethereum/aea_ledger_ethereum
PLUGIN_COSMOS_SRC := plugins/aea-ledger-cosmos/aea_ledger_cosmos
PLUGIN_CLI_IPFS_SRC := plugins/aea-cli-ipfs/aea_cli_ipfs
PLUGINS_SRC := $(PLUGIN_FETCHAI_SRC) $(PLUGIN_ETHEREUM_SRC) $(PLUGIN_COSMOS_SRC) $(PLUGIN_CLI_IPFS_SRC)
PLUGIN_FETCHAI_TESTS := plugins/aea-ledger-fetchai/tests
PLUGIN_ETHEREUM_TESTS := plugins/aea-ledger-ethereum/tests
PLUGIN_COSMOS_TESTS := plugins/aea-ledger-cosmos/tests
PLUGIN_CLI_IPFS_TESTS := plugins/aea-cli-ipfs/tests
PLUGINS_TESTS := $(PLUGIN_FETCHAI_TESTS) $(PLUGIN_ETHEREUM_TESTS) $(PLUGIN_COSMOS_TESTS) $(PLUGIN_CLI_IPFS_TESTS)
PLUGIN_FETCHAI := plugins/aea-ledger-fetchai
PLUGIN_ETHEREUM := plugins/aea-ledger-ethereum
PLUGIN_COSMOS := plugins/aea-ledger-cosmos
PLUGIN_CLI_IPFS := plugins/aea-cli-ipfs
PYTHON_CODE_DIRS := $(AEA_SRC_DIR) $(BENCHMARK_DIR) $(EXAMPLES_DIR) $(PACKAGES_DIR) $(PLUGINS_DIR) $(SCRIPTS_DIR) $(AEA_TESTS_DIR)
########################################
### 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: clean
if [ -z "$v" ];\
then\
poetry install --with dev,docs,packages,tools,testing,types;\
poetry run pip install --no-deps file:plugins/aea-ledger-ethereum;\
poetry run pip install --no-deps file:plugins/aea-ledger-cosmos;\
poetry run pip install --no-deps file:plugins/aea-ledger-fetchai;\
poetry run pip install --no-deps file:plugins/aea-cli-ipfs;\
echo "Enter virtual environment with all development dependencies now: 'poetry shell'.";\
else\
echo "In a virtual environment! Exit first: 'exit'.";\
fi
########################################
### Tests
########################################
# Run all tests
.PHONY: test
test: test-aea-all test-plugins
# Run all aea tests
.PHONY: test-aea-all
test-aea-all:
pytest -rfE --doctest-modules $(AEA_TESTS_DIR) --cov=$(AEA_SRC_DIR) --cov=$(CONNECTIONS_DIR) --cov=$(CONTRACTS_DIR) --cov=$(PROTOCOLS_DIR) --cov=$(SKILLS_DIR) --cov-report=html --cov-report=term-missing --cov-config=pyproject.toml
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
.PHONY: test-aea-core
test-aea-core:
pytest -rfE --doctest-modules $(AEA_CORE_TESTS_DIRS) --cov=$(AEA_SRC_DIR) --cov-report=html --cov-report=term-missing --cov-config=pyproject.toml
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
.PHONY: test-packages
test-packages:
pytest -rfE --doctest-modules $(PACKAGES_TESTS_DIRS) --cov=$(AEA_SRC_DIR) --cov=$(CONNECTIONS_DIR) --cov=$(CONTRACTS_DIR) --cov=$(PROTOCOLS_DIR) --cov=$(SKILLS_DIR) --cov-report=html --cov-report=term-missing --cov-config=pyproject.toml
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
.PHONY: test-docs
test-docs:
pytest -rfE --doctest-modules $(DOCS_TESTS_DIR) --cov=$(AEA_SRC_DIR) --cov-report=html --cov-report=term-missing --cov-config=pyproject.toml
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
.PHONY: test-examples
test-examples:
pytest -rfE --doctest-modules $(EXAMPLES_TESTS_DIRS) --cov=$(AEA_SRC_DIR) --cov=$(CONNECTIONS_DIR) --cov=$(CONTRACTS_DIR) --cov=$(PROTOCOLS_DIR) --cov=$(SKILLS_DIR) --cov-report=html --cov-report=term-missing --cov-config=pyproject.toml
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
# Run all plugin tests
.PHONY: test-plugins
test-plugins:
pytest -rfE $(PLUGIN_FETCHAI_TESTS) --cov=aea_ledger_fetchai --cov-report=term-missing --cov-config=pyproject.toml
pytest -rfE $(PLUGIN_ETHEREUM_TESTS) --cov=aea_ledger_ethereum --cov-report=term-missing --cov-config=pyproject.toml
pytest -rfE $(PLUGIN_COSMOS_TESTS) --cov=aea_ledger_cosmos --cov-report=term-missing --cov-config=pyproject.toml
pytest -rfE $(PLUGIN_CLI_IPFS_TESTS) --cov=aea_cli_ipfs --cov-report=term-missing --cov-config=pyproject.toml
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
# Run tests for a particular python package
.PHONY: test-sub
test-sub:
pytest -rfE --doctest-modules $(AEA_TESTS_DIR)/test_$(tdir) --cov=aea.$(dir) --cov-report=html --cov-report=term-missing --cov-config=pyproject.toml
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
# Run tests for a particular aea package
.PHONY: test-sub-p
test-sub-p:
pytest -rfE --doctest-modules $(AEA_TESTS_DIR)/test_packages/test_$(tdir) --cov=packages.fetchai.$(dir) --cov-report=html --cov-report=term-missing --cov-config=pyproject.toml
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
# Produce the coverage report. Can see a report summary on the terminal.
# Detailed report on all modules are placed under /htmlcov
.PHONY: coverage-report
coverage-report:
coverage report -m -i
coverage html
########################################
### Code Styling
########################################
# Automatically run black and isort to format the code, and run flake8 and vulture checks
.PHONY: lint
lint: black isort flake8 vulture
# Automatically format the code using black
.PHONY: black
black:
black $(PYTHON_CODE_DIRS)
# Automatically sort the imports
.PHONY: isort
isort:
isort $(PYTHON_CODE_DIRS)
# Check the code format
.PHONY: black-check
black-check:
black --check --verbose $(PYTHON_CODE_DIRS)
# Check the imports are sorted
.PHONY: isort-check
isort-check:
isort --check-only --verbose $(PYTHON_CODE_DIRS)
# Run flake8 linter
.PHONY: flake8
flake8:
flake8 $(PYTHON_CODE_DIRS)
# Check for unused code
.PHONY: vulture
vulture:
vulture $(AEA_SRC_DIR) scripts/whitelist.py --exclude '*_pb2.py'
########################################
### Security & safety checks
########################################
# Run bandit and safety
.PHONY: security
security: bandit safety
# Check the security of the code
.PHONY: bandit
bandit:
bandit -r $(AEA_SRC_DIR) $(BENCHMARK_DIR) $(EXAMPLES_DIR) $(PACKAGES_DIR) $(PLUGIN_FETCHAI_SRC) $(PLUGIN_ETHEREUM_SRC) $(PLUGIN_COSMOS_SRC) $(PLUGIN_CLI_IPFS_SRC)
bandit -s B101 -r $(AEA_TESTS_DIR) $(SCRIPTS_DIR)
# Check the security of the code for known vulnerabilities
.PHONY: safety
safety:
safety check -i 44610 -i 50473
########################################
### Linters
########################################
# Check types (statically) using mypy
.PHONY: mypy
mypy:
mypy aea packages benchmark --disallow-untyped-defs
mypy examples --check-untyped-defs
mypy scripts
mypy tests --exclude "serialization.py"
# Lint the code using pylint
.PHONY: pylint
pylint:
pylint -j0 -d E1136 $(AEA_SRC_DIR) $(BENCHMARK_DIR) $(EXAMPLES_DIR) $(PACKAGES_DIR) $(SCRIPTS_DIR) $(PLUGIN_FETCHAI_SRC) $(PLUGIN_ETHEREUM_SRC) $(PLUGIN_COSMOS_SRC) $(PLUGIN_CLI_IPFS_SRC)
########################################
### License and copyright checks
########################################
# Check dependency 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 that the relevant files have appropriate Copyright header
.PHONY: copyright-check
copyright-check:
python scripts/check_copyright_notice.py --directory .
########################################
### 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 $(args)
# Check links are live in the documentation
.PHONY: check-doc-links
check-doc-links:
python scripts/check_doc_links.py
########################################
### 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 -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 {} +
rm -rf plugins/*/build
rm -rf plugins/*/dist
.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.xml
rm -fr htmlcov/
rm -fr .hypothesis
rm -fr .pytest_cache
rm -fr .mypy_cache/
rm -fr input_file
rm -fr output_file
find . -name 'log.txt' -exec rm -fr {} +
find . -name 'log.*.txt' -exec rm -fr {} +
########################################
### Packages
########################################
# Update package hashes
.PHONY: update-package-hashes
update-package-hashes:
python scripts/generate_ipfs_hashes.py
# Run all package checks
.PHONY: package-checks
package-checks: check-package-hashes check-package-versions-in-docs check-packages
# Check package hashes
.PHONY: check-package-hashes
check-package-hashes:
python scripts/generate_ipfs_hashes.py --check
# Check correct package version in the docs
.PHONY: check-package-versions-in-docs
check-package-versions-in-docs:
python scripts/check_package_versions_in_docs.py
# Perform various checks on packages
.PHONY: check-packages
check-packages:
python scripts/check_packages.py
########################################
### Other checks
########################################
# Check that libp2p code in libs and connection aren't different
.PHONY: libp2p-diffs
libp2p-diffs:
diff libs/go/libp2p_node packages/fetchai/connections/p2p_libp2p/libp2p_node -r
# Check that plugins for Cosmos and Fetch.ai, and Plugins' and main Licenses aren't different
.PHONY: plugin-diffs
plugin-diffs:
diff $(PLUGIN_COSMOS_SRC)/cosmos.py $(PLUGIN_FETCHAI_SRC)/_cosmos.py
diff LICENSE $(PLUGIN_COSMOS)/LICENSE
diff LICENSE $(PLUGIN_ETHEREUM)/LICENSE
diff LICENSE $(PLUGIN_FETCHAI)/LICENSE
########################################
### Build
########################################
# Build the project
.PHONY: dist
dist: clean
poetry build
protolint_install:
GO111MODULE=on GOPATH=~/go go install github.com/yoheimuta/protolint/cmd/[email protected]
protolint:
PATH=${PATH}:${GOPATH}/bin/:~/go/bin protolint lint -config_path=./protolint.yaml -fix ./aea/mail ./packages/fetchai/protocols
protolint_install_win:
powershell -command '$$env:GO111MODULE="on"; go install github.com/yoheimuta/protolint/cmd/[email protected]'
protolint_win:
protolint lint -config_path=./protolint.yaml -fix ./aea/mail ./packages/fetchai/protocols