-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
238 lines (184 loc) · 7.33 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
# Autodocumented Makefile
# see: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
# Dependencies : python3 venv
# Some Makefile global variables can be set in make command line
# Recall: .PHONY defines special targets not associated with files
############### GLOBAL VARIABLES ######################
.DEFAULT_GOAL := help
# Set shell to BASH
SHELL := /bin/bash
# Set Virtualenv directory name
# Exemple: VENV="other-venv/" make install
ifndef VENV
VENV = "venv"
endif
# Browser definition
define BROWSER_PYSCRIPT
import os, webbrowser, sys
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
# Python global variables definition
PYTHON_VERSION_MIN = 3.8
# Set PYTHON if not defined in command line
# Example: PYTHON="python3.10" make venv to use python 3.10 for the venv
# By default the default python3 of the system.
ifndef PYTHON
PYTHON = "python3"
endif
PYTHON_CMD=$(shell command -v $(PYTHON))
PYTHON_VERSION_CUR=$(shell $(PYTHON_CMD) -c 'import sys; print("%d.%d"% sys.version_info[0:2])')
PYTHON_VERSION_OK=$(shell $(PYTHON_CMD) -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))')
############### Check python version supported ############
ifeq (, $(PYTHON_CMD))
$(error "$(PYTHON_CMD) not found in $(PATH)")
endif
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 "CARS-MESH MAKE HELP"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
## Install section
.PHONY: venv
venv: ## create virtualenv in "venv" dir if not exists
@test -d ${VENV} || $(PYTHON_CMD) -m venv ${VENV}
@${VENV}/bin/python -m pip install --upgrade pip setuptools # no check to upgrade each time
@touch ${VENV}/bin/activate
.PHONY: install
install: venv ## install the package in dev mode in virtualenv
@test -f ${VENV}/bin/cars-mesh || echo "Install cars-mesh package from local directory"
@test -f ${VENV}/bin/cars-mesh || ${VENV}/bin/python -m pip install -e .[dev,docs]
@test -f .git/hooks/pre-commit || echo "Install pre-commit"
@test -f .git/hooks/pre-commit || ${VENV}/bin/pre-commit install -t pre-commit
@test -f .git/hooks/pre-push || ${VENV}/bin/pre-commit install -t pre-push
@echo "cars-mesh installed in dev mode in virtualenv ${VENV} with documentation"
@echo " cars-mesh venv usage : source ${VENV}/bin/activate; cars-mesh -h"
## Test section
.PHONY: test
test: ## run tests and coverage quickly with the default python3 (only slow test)
@${VENV}/bin/pytest -m fast -o log_cli=true --cov-config=.coveragerc --cov --cov-report=term-missing
.PHONY: test-all
test-all: ## run all tests and coverage with the default python3 (slow and fast)
@${VENV}/bin/pytest -o log_cli=true --cov-config=.coveragerc --cov --cov-report=term-missing
.PHONY: tox
tox: ## run tests via tox on every python version (only slow test)
@${VENV}/bin/tox -r -p auto -- -m slow ## recreate venv (-r) and parallel mode (-p auto)
.PHONY: tox-all
tox-all: ## run all tests on every Python version with tox
@${VENV}/bin/tox -r -p auto ## recreate venv (-r) and parallel mode (-p auto)
.PHONY: coverage
coverage: ## check code coverage quickly with the default Python
@${VENV}/bin/coverage run --source cars_mesh -m pytest
@${VENV}/bin/coverage report -m
@${VENV}/bin/coverage html
$(BROWSER) htmlcov/index.html
## Code quality, linting section
### Format with isort and black
.PHONY: format
format: format/isort format/black ## run black and isort formatting (depends install)
.PHONY: format/isort
format/isort: install ## run isort formatting (depends install)
@echo "+ $@"
@${VENV}/bin/isort cars_mesh tests
.PHONY: format/black
format/black: install ## run black formatting (depends install)
@echo "+ $@"
@${VENV}/bin/black cars_mesh tests
### Check code quality and linting : isort, black, flake8, pylint
.PHONY: lint
lint: lint/isort lint/black lint/flake8 lint/pylint ## check code quality and linting
.PHONY: lint/isort
lint/isort: ## check imports style with isort
@echo "+ $@"
@${VENV}/bin/isort --check cars_mesh tests
.PHONY: lint/black
lint/black: ## check global style with black
@echo "+ $@"
@${VENV}/bin/black --check cars_mesh tests
.PHONY: lint/flake8
lint/flake8: ## check linting with flake8
@echo "+ $@"
@${VENV}/bin/flake8 cars_mesh tests
.PHONY: lint/pylint
lint/pylint: ## check linting with pylint
@echo "+ $@"
@set -o pipefail; ${VENV}/bin/pylint cars_mesh tests --rcfile=.pylintrc --output-format=parseable | tee pylint-report.txt # pipefail to propagate pylint exit code in bash
## Documentation section
.PHONY: docs
docs: ## generate Sphinx HTML documentation, including API docs
@${VENV}/bin/sphinx-build -M clean docs/source/ docs/build
@${VENV}/bin/sphinx-build -M html docs/source/ docs/build -W --keep-going
$(BROWSER) docs/build/html/index.html
## Notebook section
notebook: ## Install Jupyter notebook kernel with venv
@echo "Install Jupyter Kernel and run Jupyter notebooks environment"
@${VENV}/bin/python -m ipykernel install --sys-prefix --name=cars-mesh$(VENV) --display-name=cars-mesh$(VERSION)
@echo " --> After virtualenv activation, please use following command to run local jupyter notebook to open Notebooks:"
@echo "jupyter notebook"
## Docker section
docker: git ## Build docker image (and check Dockerfile)
@echo "Check Dockerfile with hadolint"
@docker pull hadolint/hadolint
@docker run --rm -i hadolint/hadolint < Dockerfile
@echo "Build Docker image cars-mesh"
@docker build -t cnes/cars-mesh:dev -t cnes/cars-mesh:latest .
## Release section
.PHONY: dist
dist: clean install ## clean, install, builds source and wheel package
@${VENV}/bin/python -m pip install --upgrade build
@${VENV}/bin/python -m build
ls -l dist
.PHONY: release
release: dist ## package and upload a release
@twine check dist/*
@twine upload dist/* --verbose ## update your .pypirc accordingly
## Clean section
.PHONY: clean
clean: clean-venv clean-build clean-pyc clean-test clean-docs ## remove all build, test, coverage and Python artifacts
.PHONY: clean-venv
clean-venv:
@echo "+ $@"
@rm -rf ${VENV}
.PHONY: clean-build
clean-build: ## remove build artifacts
@echo "+ $@"
@rm -fr build/
@rm -fr dist/
@rm -fr .eggs/
@find . -name '*.egg-info' -exec rm -fr {} +
@find . -name '*.egg' -exec rm -fr {} +
.PHONY: clean-pyc
clean-pyc: ## remove Python file artifacts
@echo "+ $@"
@find . -type f -name "*.py[co]" -delete
@find . -type d -name "__pycache__" -delete
@find . -name '*~' -delete
.PHONY: clean-test
clean-test: ## remove test and coverage artifacts
@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-docs
clean-docs:
@echo "+ $@"
@rm -rf docs/build/
@rm -rf docs/source/api_reference/
@rm -rf docs/source/apidoc/
.PHONY: clean-docker
clean-docker:
@echo "+ $@"
@echo "Clean Docker image cars-mesh"
@docker image rm cnes/cars-mesh:dev
@docker image rm cnes/cars-mesh:latest