-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
101 lines (89 loc) · 2.83 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
.PHONY: help lint test docs check clean
ifdef NOCOLOR
NC=
ERROR=[ERROR]
INFO=[INFO]
WARNING=[WARNING]
$(info $(INFO) Output coloring is disabled.)
else
NC=$(shell printf "\033[0m")
ERROR=$(shell printf "\033[1;31m")[ERROR]$(NC)
INFO=$(shell printf "\033[1;32m")[INFO]$(NC)
WARNING=$(shell printf "\033[1;33m")[WARNING]$(NC)
$(info $(INFO) Output coloring is enabled. Pass NOCOLOR=true to disable.)
endif
POETRY_PYTHON=$(shell poetry run which python)
PYTHON_IMPLEMENTATION=$(shell $(POETRY_PYTHON) -c "import sys;print(sys.implementation.name)")
MYPY_CMD="$(POETRY_PYTHON) -m mypy"
VENV_SITE_PACKAGES=$(shell poetry run python -c "import site; print(site.getsitepackages()[0])")
ifneq ($(shell $(POETRY_PYTHON) -m mypy -V 2>/dev/null; echo $$?), 0)
ifneq (, $(shell which mypy))
MYPY_CMD=$(shell which mypy)
else
MYPY_CMD=
endif
endif
ifneq ($(shell $(POETRY_PYTHON) -m mypy -V 2>/dev/null; echo $$?), 0)
WHICH_BLACK=$(shell which black)
ifneq (, $$WHICH_BLACK)
BLACK_CMD=$(WHICH_BLACK)
else
BLACK_CMD=
endif
endif
SRC_DIR=snecs
TESTS_DIR=tests
DOCS_DIR=docs
help:
@printf "make help - display this message\n"
@printf "make test - run tests\n"
@printf "make lint - run linters\n"
@printf "make check - run linters AND tests\n"
@printf "make docs - build documentation\n"
@printf "make docs - remove documentation build directory\n"
# Run all linters (isort, black, flake8, mypy) without early-exiting if
# any of them fails.
lint: $(VENV_SITE_PACKAGES)/flake8 $(VENV_SITE_PACKAGES)/isort
@STATUS=0; \
printf "$(INFO) Running isort.$(NC)\n"; \
poetry run isort -ac -rc $(SRC_DIR) $(TESTS_DIR) $(DOCS_DIR) || { \
STATUS=$$?; printf "$(ERROR) isort failed.\n"; \
}; \
if ! [[ -z "$(BLACK_CMD)" ]]; then \
printf "$(INFO) Running black.$(NC)\n"; \
$(BLACK_CMD) $(SRC_DIR) $(TESTS_DIR) $(DOCS_DIR) || { \
STATUS=$$?; printf "$(WARN) Reformatted sources.\n"; \
}; \
fi; \
printf "$(INFO) Running flake8.$(NC)\n"; \
poetry run flake8 $(SRC_DIR) || { \
STATUS=$$?; printf "$(ERROR) flake8 failed.\n"; \
}; \
if ! [[ -z "$(MYPY_CMD)" ]]; then \
printf "$(INFO) Running mypy.$(NC)\n"; \
$(MYPY_CMD) $(SRC_DIR) || { \
STATUS=$$?; printf "$(ERROR) mypy failed.\n"; \
}; \
fi; \
if [[ $$STATUS -eq 0 ]]; then \
printf "$(INFO) No lint issues found.$(NC)\n"; \
else \
printf "$(ERROR) Encountered issues.$(NC)\n"; \
exit $$STATUS; \
fi
$(VENV_SITE_PACKAGES)/%:
@printf "$(INFO) Installing dev dependencies.$(NC)\n"
@poetry install
@printf "$(INFO) Done.$(NC)\n"
docs: $(VENV_SITE_PACKAGES)/sphinxcontrib
sphinx-build $(DOCS_DIR) $(DOCS_DIR)/_build/ -a -b dirhtml
clean:
rm -rf $(DOCS_DIR)/_build/*
test: $(VENV_SITE_PACKAGES)/pytest
poetry run pytest \
--ignore=tests/test_benchmarks.py \
--benchmark-disable \
--cov=$(SRC_DIR) \
--cov-report html \
--tb=short tests
check: lint test