-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
149 lines (117 loc) · 4.72 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
# Autodocumented Makefile
# see: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
#
# Dependencies : python3 venv internal module
# Recall: .PHONY defines special targets not associated with files
#
# Some Makefile global variables can be set in make command line:
# PLUGIN_ARNN_VENV: Change directory of installed venv (default local "venv" dir)
#
############### GLOBAL VARIABLES ######################
.DEFAULT_GOAL := help
# Set shell to BASH
SHELL := /bin/bash
# Set Virtualenv directory name
# Example: PLUGIN_ARNN_VENV="other-venv/" make install
ifndef PLUGIN_ARNN_VENV
PLUGIN_ARNN_VENV = "venv"
endif
# Check if plugin is installed
CHECK_PLUGIN_ARNN = $(shell ${PLUGIN_ARNN_VENV}/bin/python3 -m pip list|grep pandora_plugin_arnn)
# Check python3 globally
PYTHON=$(shell command -v python3)
ifeq (, $(PYTHON))
$(error "PYTHON=$(PYTHON) not found in $(PATH)")
endif
# Check Python version supported globally
PYTHON_VERSION_MIN = 3.8
PYTHON_VERSION_CUR=$(shell $(PYTHON) -c 'import sys; print("%d.%d"% sys.version_info[0:2])')
PYTHON_VERSION_OK=$(shell $(PYTHON) -c 'import sys; cur_ver = sys.version_info[0:2]; min_ver = tuple(map(int, "$(PYTHON_VERSION_MIN)".split("."))); print(int(cur_ver >= min_ver))')
ifeq ($(PYTHON_VERSION_OK), 0)
$(error "Requires python version >= $(PYTHON_VERSION_MIN). Current version is $(PYTHON_VERSION_CUR)")
endif
################ MAKE targets by sections ######################
.PHONY: help
help: ## this help
@echo " PANDORA MAKE HELP"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'| sort
## Install section
.PHONY: venv
venv: ## create virtualenv in PLUGIN_ARNN_VENV directory if not exists
@test -d ${PLUGIN_ARNN_VENV} || python3 -m venv ${PLUGIN_ARNN_VENV}
@${PLUGIN_ARNN_VENV}/bin/python -m pip install --upgrade pip setuptools wheel # no check to upgrade each time
@touch ${PLUGIN_ARNN_VENV}/bin/activate
.PHONY: install
install: venv ## install pandora_plugin_arnn (pip editable mode) without plugins
@[ "${CHECK_PLUGIN_ARNN}" ] || ${PLUGIN_ARNN_VENV}/bin/pip install -e .[dev,docs]
@test -f .git/hooks/pre-commit || echo " Install pre-commit hook"
@test -f .git/hooks/pre-commit || ${PLUGIN_ARNN_VENV}/bin/pre-commit install
@echo "PANDORA installed in dev mode in virtualenv ${PLUGIN_ARNN_VENV}"
@echo "PANDORA venv usage : source ${PLUGIN_ARNN_VENV}/bin/activate; python -c 'import pandora_plugin_arnn' "
## Test section
.PHONY: test
test: install ## run all tests + coverage (source venv before)
@${PLUGIN_ARNN_VENV}/bin/pytest --junitxml=pytest-report.xml --cov-config=.coveragerc --cov-report xml --cov
## Code quality, linting section
### Format with black
.PHONY: format
format: install format/black ## run black formatting (depends install)
.PHONY: format/black
format/black: install ## run black formatting (depends install) (source venv before)
@echo "+ $@"
@${PLUGIN_ARNN_VENV}/bin/black pandora_plugin_arnn tests ./*.py
### Check code quality and linting : black, mypy, pylint
.PHONY: lint
lint: install lint/black lint/pylint ## check code quality and linting (mypy deactivated!) (source venv before)
.PHONY: lint/black
lint/black: ## check global style with black
@echo "+ $@"
@${PLUGIN_ARNN_VENV}/bin/black --check pandora_plugin_arnn tests ./*.py
.PHONY: lint/mypy
lint/mypy: ## check linting with mypy
@echo "+ $@"
@${PLUGIN_ARNN_VENV}/bin/mypy pandora_plugin_arnn tests
.PHONY: lint/pylint
lint/pylint: ## check linting with pylint
@echo "+ $@"
@set -o pipefail; ${PLUGIN_ARNN_VENV}/bin/pylint pandora_plugin_arnn tests --rcfile=.pylintrc --output-format=parseable --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" | tee pylint-report.txt # pipefail to propagate pylint exit code in bash
## Clean section
.PHONY: clean
clean: clean-venv clean-build clean-precommit clean-pyc clean-test clean-mypy ## remove all build, test, coverage and Python artifacts
.PHONY: clean-venv
clean-venv:
@echo "+ $@"
@rm -rf ${PLUGIN_ARNN_VENV}
.PHONY: clean-build
clean-build:
@echo "+ $@"
@rm -fr build/
@rm -fr .eggs/
@find . -name '*.egg-info' -exec rm -fr {} +
@find . -name '*.egg' -exec rm -f {} +
.PHONY: clean-precommit
clean-precommit:
@rm -f .git/hooks/pre-commit
@rm -f .git/hooks/pre-push
.PHONY: clean-pyc
clean-pyc:
@echo "+ $@"
@find . -type f -name "*.py[co]" -exec rm -fr {} +
@find . -type d -name "__pycache__" -exec rm -fr {} +
@find . -name '*~' -exec rm -fr {} +
.PHONY: clean-test
clean-test:
@echo "+ $@"
@rm -fr .tox/
@rm -f .coverage
@rm -rf .coverage.*
@rm -rf coverage.xml
@rm -fr htmlcov/
@rm -fr .pytest_cache
@rm -f pytest-report.xml
@rm -f pylint-report.txt
@rm -f debug.log
.PHONY: clean-mypy
clean-mypy:
@echo "+ $@"
@rm -rf .mypy_cache/