-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.python
156 lines (135 loc) · 4.9 KB
/
Makefile.python
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
ifneq (,)
.error This Makefile requires GNU Make.
endif
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
# -------------------------------------------------------------------------------------------------
# Default configuration
# -------------------------------------------------------------------------------------------------
# MyPy
MYPY_VERSION = latest
MYPY_ARGS =
MYPY_DIR = .
# Pylint
PYLINT_VERSION = latest
PYLINT_PIP_PKGS =
PYLINT_ARGS =
PYLINT_DIR = .
# PyCodeStyle
PYCODE_VERSION = latest
PYCODE_ARGS =
PYCODE_DIR = .
# Black
BLACK_VERSION = latest
BLACK_LINT_ARGS = --check --diff
BLACK_FIX_ARGS =
BLACK_DIR = .
# -------------------------------------------------------------------------------------------------
# Lint Targets
# -------------------------------------------------------------------------------------------------
.PHONY: lint
lint:: lint-mypy
lint:: lint-pylint
lint:: lint-pycode
lint:: lint-black
.PHONY: lint-mypy
lint-mypy: _lint-mypy-pull
lint-mypy:
@echo "################################################################################"
@echo "# Lint MyPy"
@echo "################################################################################"
docker run --rm $$(tty -s && echo "-it" || echo) -e PIP_ROOT_USER_ACTION=ignore -v $$(pwd):/data -w /data cytopia/mypy:$(MYPY_VERSION) \
--install-types \
--non-interactive \
$(MYPY_ARGS) $(MYPY_DIR)
.PHONY: lint-pylint
lint-pylint: _lint-pylint-pull
lint-pylint:
@echo "################################################################################"
@echo "# Lint Pylint"
@echo "################################################################################"
docker run --rm $$(tty -s && echo "-it" || echo) -e PIP_ROOT_USER_ACTION=ignore -v $$(pwd):/data -w /data --entrypoint=sh cytopia/pylint:$(PYLINT_VERSION) \
-c 'for pkg in $(PYLINT_PIP_PKGS); do python3 -m pip install $${pkg}; done && pylint $(PYLINT_ARGS) $(PYLINT_DIR)'
.PHONY: lint-pycode
lint-pycode: _lint-pycode-pull
lint-pycode:
@echo "################################################################################"
@echo "# Lint PyCodeStyle"
@echo "################################################################################"
docker run --rm $$(tty -s && echo "-it" || echo) -e PIP_ROOT_USER_ACTION=ignore -v $$(pwd):/data -w /data cytopia/pycodestyle:$(PYCODE_VERSION) \
$(PYCODE_ARGS) \
$(PYCODE_DIR)
.PHONY: lint-black
lint-black: _lint-black-pull
lint-black:
@echo "################################################################################"
@echo "# Lint Python Black"
@echo "################################################################################"
docker run --rm $$(tty -s && echo "-it" || echo) -e PIP_ROOT_USER_ACTION=ignore -v $$(pwd):/data -w /data cytopia/black:$(BLACK_VERSION) \
$(BLACK_LINT_ARGS) \
$(BLACK_DIR)
# -------------------------------------------------------------------------------------------------
# Fix Targets
# -------------------------------------------------------------------------------------------------
.PHONY: fix
fix:: fix-black
fix-black: _lint-black-pull
fix-black:
@echo "################################################################################"
@echo "# Fix Python Black"
@echo "################################################################################"
docker run --rm $$(tty -s && echo "-it" || echo) -e PIP_ROOT_USER_ACTION=ignore -v $$(pwd):/data -w /data cytopia/black:$(BLACK_VERSION) \
$(BLACK_FIX_ARGS) \
$(BLACK_DIR)
# -------------------------------------------------------------------------------------------------
# Helper Targets
# -------------------------------------------------------------------------------------------------
.PHONY: _lint-mypy-pull
_lint-mypy-pull:
@echo "Pulling cytopia/mypy:$(MYPY_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q cytopia/mypy:$(MYPY_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
.PHONY: _lint-pylint-pull
_lint-pylint-pull:
@echo "Pulling cytopia/pylint:$(PYLINT_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q cytopia/pylint:$(PYLINT_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
.PHONY: _lint-pycode-pull
_lint-pycode-pull:
@echo "Pulling cytopia/pycodestyle:$(PYCODE_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q cytopia/pycodestyle:$(PYCODE_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
.PHONY: _lint-black-pull
_lint-black-pull:
@echo "Pulling cytopia/black:$(BLACK_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q cytopia/black:$(BLACK_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;