From 9b94f331c9aece6b05298e08d4fc5d16fe0440ef Mon Sep 17 00:00:00 2001 From: "Yuri (solarw) Turchenkov" Date: Wed, 14 Sep 2022 11:19:14 +1000 Subject: [PATCH 1/3] Makefile review and improvement --- Makefile | 64 ++++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index a7f99079..04e07e6a 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ PYCOSM_TESTS_DIR := tests PYCOSM_EXAMPLES_DIR := examples REQUIREMENTS_FILES := requirements.txt requirements-dev.txt +# python code directories +PYTHON_CODE_DIRS := $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) + ifeq ($(OS),Windows_NT) $(error "Please use the WSL (Windows Subsystem for Linux) on Windows platform.") else @@ -80,24 +83,32 @@ $(IBCGO_DIR): Makefile cd $(IBCGO_DIR) && git checkout $(IBCGO_VERSION) -- $(IBCGO_PROTO_RELATIVE_DIRS) #################### -### Code style +### Code style checks #################### .PHONY: black-check black-check: - black --check --verbose $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) --exclude $(OUTPUT_FOLDER) + black --check --verbose $(PYTHON_CODE_DIRS) --exclude $(OUTPUT_FOLDER) + +.PHONY: black +black: + black $(PYTHON_CODE_DIRS) --exclude $(OUTPUT_FOLDER) .PHONY: isort-check isort-check: - isort --check-only --verbose $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) + isort --check-only --verbose $(PYTHON_CODE_DIRS) + +.PHONY: isort +isort: + isort $(PYTHON_CODE_DIRS) -.PHONY: flake +.PHONY: flake8 flake: - flake8 $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) + flake8 $(PYTHON_CODE_DIRS) .PHONY: vulture vulture: - vulture $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100 + vulture $(PYTHON_CODE_DIRS) --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100 #################### ### Security & Safety @@ -118,11 +129,11 @@ safety: .PHONY: mypy mypy: - mypy $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) + mypy $(PYTHON_CODE_DIRS) .PHONY: pylint pylint: - pylint $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) + pylint $(PYTHON_CODE_DIRS) #################### ### Tests @@ -177,7 +188,7 @@ docs-live: #################### .PHONY: clean -clean: clean-build clean-pyc clean-test +clean: clean-build clean-pyc clean-test clean-docs .PHONY: clean-build clean-build: @@ -215,20 +226,13 @@ clean-test: v := $(shell pip -V | grep virtualenvs) .PHONY: new_env -new_env: clean - if [ -z "$v" ];\ - then\ - poetry install --only main --sync;\ - echo "Enter virtual environment with all development dependencies now: 'poetry shell'.";\ - else\ - echo "In a virtual environment! Exit first: 'exit'.";\ - fi +new_env: clean new_env_dev .PHONY: new_env_dev new_env_dev: clean if [ -z "$v" ];\ then\ - poetry install --with main, dev, test, docs --sync;\ + 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'.";\ @@ -239,32 +243,14 @@ new_env_dev: clean #################### .PHONY: lint -lint: - black $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) --exclude $(OUTPUT_FOLDER) - isort $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) - flake8 $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) - vulture $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100 +lint: black isort flake8 vulture .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 +security: bandit safety .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 +check: black-check isort-check flake8 vulture bandit safety mypy pylint liccheck copyright-check test poetry.lock: pyproject.toml poetry lock From f9a5fca88dfc5c416cf9f79a665d1ab4a1c74ba1 Mon Sep 17 00:00:00 2001 From: ali Date: Thu, 15 Sep 2022 18:13:31 +0100 Subject: [PATCH 2/3] reorder makefile commands and update makefile target names --- Makefile | 335 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 171 insertions(+), 164 deletions(-) diff --git a/Makefile b/Makefile index 04e07e6a..1839400a 100644 --- a/Makefile +++ b/Makefile @@ -1,107 +1,72 @@ -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 - -# python code directories -PYTHON_CODE_DIRS := $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_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 +######################################## +### Initialise dev environment +######################################## -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))) +v := $(shell pip -V | grep virtualenvs) -proto: fetch_proto_schema_source generate_proto_types generate_init_py_files +.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 -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) +######################################## +### Useful linting command +######################################## -fetch_proto_schema_source: $(COSMOS_SDK_DIR) $(WASMD_DIR) $(IBCGO_DIR) +.PHONY: lint +lint: black isort flake8 vulture -.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 +######################################## +### Tests +######################################## -$(SOURCE): $(COSMOS_SDK_DIR) +.PHONY: test +test: + coverage run -m pytest $(COSMPY_TESTS_DIR) --doctest-modules --ignore $(COSMPY_TESTS_DIR)/vulture_whitelist.py + $(MAKE) coverage-report -$(GENERATED): $(SOURCE) - $(COMPILE_PROTOBUFS_COMMAND) +.PHONY: unit-test +unit-test: + coverage run -m pytest $(COSMPY_TESTS_DIR) --doctest-modules --ignore $(COSMPY_TESTS_DIR)/vulture_whitelist.py -m "not integration" -$(INIT_PY_FILES_TO_CREATE): $(GENERATED_DIRS) - touch $(INIT_PY_FILES_TO_CREATE) +.PHONY: integration-test +integration-test: + coverage run -m pytest $(COSMPY_TESTS_DIR) --doctest-modules --ignore $(COSMPY_TESTS_DIR)/vulture_whitelist.py -m "integration" -$(GENERATED_DIRS): $(COSMOS_SDK_DIR) $(WASMD_DIR) $(IBCGO_DIR) +.PHONY: coverage-report +coverage-report: + coverage report -m + coverage html -$(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) +######################################## +### Automatic Styling +######################################## -$(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) +.PHONY: black +black: + black $(PYTHON_CODE_DIRS) --exclude $(COSMPY_PROTOS_DIR) -$(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) +.PHONY: isort +isort: + isort $(PYTHON_CODE_DIRS) -#################### +######################################## ### Code style checks -#################### +######################################## .PHONY: black-check black-check: - black --check --verbose $(PYTHON_CODE_DIRS) --exclude $(OUTPUT_FOLDER) - -.PHONY: black -black: - black $(PYTHON_CODE_DIRS) --exclude $(OUTPUT_FOLDER) + black --check --verbose $(PYTHON_CODE_DIRS) --exclude $(COSMPY_PROTOS_DIR) .PHONY: isort-check isort-check: isort --check-only --verbose $(PYTHON_CODE_DIRS) -.PHONY: isort -isort: - isort $(PYTHON_CODE_DIRS) - .PHONY: flake8 flake: flake8 $(PYTHON_CODE_DIRS) @@ -110,22 +75,25 @@ flake: vulture: vulture $(PYTHON_CODE_DIRS) --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100 -#################### -### Security & Safety -#################### +######################################## +### Security & safety checks +######################################## + +.PHONY: security +security: bandit safety .PHONY: bandit bandit: - bandit -r $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) --skip B101 - bandit -r $(PYCOSM_EXAMPLES_DIR) --skip B101,B105 + bandit -r $(COSMPY_SRC_DIR) $(COSMPY_TESTS_DIR) --skip B101 + bandit -r $(COSMPY_EXAMPLES_DIR) --skip B101,B105 .PHONY: safety safety: safety check -i 41002 -#################### +######################################## ### Linters -#################### +######################################## .PHONY: mypy mypy: @@ -135,125 +103,164 @@ mypy: pylint: pylint $(PYTHON_CODE_DIRS) -#################### -### 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: poetry export > tmp-requirements.txt liccheck -s strategy.ini -r tmp-requirements.txt -l PARANOID + rm -frv tmp-requirements.txt .PHONY: copyright-check copyright-check: python scripts/check_copyright.py -#################### -### Docs generation -#################### +######################################## +### Docs +######################################## .PHONY: docs docs: mkdocs build --clean - .PHONY: docs-live docs-live: mkdocs serve -#################### -### Clean and init commands -#################### +######################################## +### Update Poetry Lock +######################################## + +poetry.lock: pyproject.toml + poetry lock + +######################################## +### Clear the caches and temporary files +######################################## .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 -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 -fr site/ + rm -frv 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 {} + + 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 -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 {} + + 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 +######################################## -v := $(shell pip -V | grep virtualenvs) +COSMOS_SDK_URL := https://github.com/fetchai/cosmos-sdk +COSMOS_SDK_VERSION := v0.18.0 +COSMOS_SDK_DIR := build/cosmos-sdk-proto-schema -.PHONY: new_env -new_env: clean new_env_dev +WASMD_URL := https://github.com/CosmWasm/wasmd +WASMD_VERSION := v0.24.0 +WASMD_DIR := build/wasm-proto-shema -.PHONY: new_env_dev -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 +IBCGO_URL := https://github.com/cosmos/ibc-go +IBCGO_VERSION := v2.2.0 +IBCGO_DIR := build/ibcgo-proto-schema -#################### -### Combinations -#################### +COSMPY_PROTOS_DIR := cosmpy/protos +COSMPY_SRC_DIR := cosmpy -.PHONY: lint -lint: black isort flake8 vulture +COSMPY_TESTS_DIR := tests +COSMPY_EXAMPLES_DIR := examples -.PHONY: security -security: bandit safety +# python code directories +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))) -.PHONY: check -check: black-check isort-check flake8 vulture bandit safety mypy pylint liccheck copyright-check test +proto: fetch_proto_schema_source generate_proto_types generate_init_py_files -poetry.lock: pyproject.toml - poetry lock +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)) From df11b6b48f5c69a3e05c1f7270a81fac732c3037 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 21 Sep 2022 17:17:25 +0100 Subject: [PATCH 3/3] add comments for commands and add command for API docs --- Makefile | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1839400a..a3ddd95b 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ ### 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 @@ -18,6 +20,7 @@ new_env_dev: clean ### 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 @@ -25,19 +28,24 @@ 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 @@ -47,10 +55,12 @@ coverage-report: ### 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) @@ -59,18 +69,22 @@ isort: ### 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 @@ -79,14 +93,13 @@ vulture: ### Security & safety checks ######################################## -.PHONY: security -security: bandit safety - +# 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 @@ -95,10 +108,12 @@ safety: ### Linters ######################################## +# Runs the mypy linter .PHONY: mypy mypy: mypy $(PYTHON_CODE_DIRS) +# Runs the pylint linter .PHONY: pylint pylint: pylint $(PYTHON_CODE_DIRS) @@ -107,12 +122,14 @@ pylint: ### 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 @@ -121,18 +138,26 @@ copyright-check: ### 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 @@ -140,6 +165,7 @@ poetry.lock: pyproject.toml ### 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 @@ -180,6 +206,7 @@ clean-test: ### Generate protos and grpc files ######################################## +# Constants COSMOS_SDK_URL := https://github.com/fetchai/cosmos-sdk COSMOS_SDK_VERSION := v0.18.0 COSMOS_SDK_DIR := build/cosmos-sdk-proto-schema @@ -198,7 +225,6 @@ COSMPY_SRC_DIR := cosmpy COSMPY_TESTS_DIR := tests COSMPY_EXAMPLES_DIR := examples -# python code directories PYTHON_CODE_DIRS := $(COSMPY_SRC_DIR) $(COSMPY_TESTS_DIR) $(COSMPY_EXAMPLES_DIR) ifeq ($(OS),Windows_NT)