This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
150 lines (125 loc) · 3.39 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
SHELL := /usr/bin/env bash
IMAGE := mongomantic
VERSION := latest
#! An ugly hack to create individual flags
ifeq ($(STRICT), 1)
POETRY_COMMAND_FLAG =
PIP_COMMAND_FLAG =
SAFETY_COMMAND_FLAG =
BANDIT_COMMAND_FLAG =
SECRETS_COMMAND_FLAG =
BLACK_COMMAND_FLAG =
DARGLINT_COMMAND_FLAG =
ISORT_COMMAND_FLAG =
MYPY_COMMAND_FLAG =
else
POETRY_COMMAND_FLAG = -
PIP_COMMAND_FLAG = -
SAFETY_COMMAND_FLAG = -
BANDIT_COMMAND_FLAG = -
SECRETS_COMMAND_FLAG = -
BLACK_COMMAND_FLAG = -
DARGLINT_COMMAND_FLAG = -
ISORT_COMMAND_FLAG = -
MYPY_COMMAND_FLAG = -
endif
##! Please tell me how to use `for loops` to create variables in Makefile :(
##! If you have better idea, please PR me in https://github.com/TezRomacH/python-package-template
ifeq ($(POETRY_STRICT), 1)
POETRY_COMMAND_FLAG =
else ifeq ($(POETRY_STRICT), 0)
POETRY_COMMAND_FLAG = -
endif
ifeq ($(PIP_STRICT), 1)
PIP_COMMAND_FLAG =
else ifeq ($(PIP_STRICT), 0)
PIP_COMMAND_FLAG = -
endif
ifeq ($(SAFETY_STRICT), 1)
SAFETY_COMMAND_FLAG =
else ifeq ($(SAFETY_STRICT), 0)
SAFETY_COMMAND_FLAG = -
endif
ifeq ($(BANDIT_STRICT), 1)
BANDIT_COMMAND_FLAG =
else ifeq ($(BANDIT_STRICT), 0)
BANDIT_COMMAND_FLAG = -
endif
ifeq ($(SECRETS_STRICT), 1)
SECRETS_COMMAND_FLAG =
else ifeq ($(SECRETS_STRICT), 0)
SECRETS_COMMAND_FLAG = -
endif
ifeq ($(BLACK_STRICT), 1)
BLACK_COMMAND_FLAG =
else ifeq ($(BLACK_STRICT), 0)
BLACK_COMMAND_FLAG = -
endif
ifeq ($(DARGLINT_STRICT), 1)
DARGLINT_COMMAND_FLAG =
else ifeq ($(DARGLINT_STRICT), 0)
DARGLINT_COMMAND_FLAG = -
endif
ifeq ($(ISORT_STRICT), 1)
ISORT_COMMAND_FLAG =
else ifeq ($(ISORT_STRICT), 0)
ISORT_COMMAND_FLAG = -
endif
ifeq ($(MYPY_STRICT), 1)
MYPY_COMMAND_FLAG =
else ifeq ($(MYPY_STRICT), 0)
MYPY_COMMAND_FLAG = -
endif
#! The end of the ugly part. I'm really sorry
.PHONY: download-poetry
download-poetry:
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
.PHONY: install
install:
poetry lock -n
poetry install -n
ifneq ($(NO_PRE_COMMIT), 1)
poetry run pre-commit install
endif
.PHONY: check-safety
check-safety:
$(POETRY_COMMAND_FLAG)poetry check
$(PIP_COMMAND_FLAG)poetry run pip check
$(SAFETY_COMMAND_FLAG)poetry run safety check --full-report
$(BANDIT_COMMAND_FLAG)poetry run bandit -ll -r mongomantic/
.PHONY: check-style
check-style:
echo $(PWD)
$(BLACK_COMMAND_FLAG)poetry run black --config pyproject.toml --diff --check ./
$(DARGLINT_COMMAND_FLAG)poetry run darglint -v 2 **/*.py
$(ISORT_COMMAND_FLAG)poetry run isort --settings-path pyproject.toml --check-only **/*.py
$(MYPY_COMMAND_FLAG)poetry run flake8 --config setup.cfg mongomantic/**/*.py
.PHONY: codestyle
codestyle:
-poetry run pyupgrade --py37-plus **/*.py
poetry run isort --settings-path pyproject.toml **/*.py
poetry run black --config pyproject.toml ./
.PHONY: test
test:
poetry run pytest
.PHONY: lint
lint: test check-safety check-style
# Example: make docker VERSION=latest
# Example: make docker IMAGE=some_name VERSION=0.1.0
.PHONY: docker
docker:
@echo Building docker $(IMAGE):$(VERSION) ...
docker build \
-t $(IMAGE):$(VERSION) . \
-f ./docker/Dockerfile --no-cache
# Example: make clean_docker VERSION=latest
# Example: make clean_docker IMAGE=some_name VERSION=0.1.0
.PHONY: clean_docker
clean_docker:
@echo Removing docker $(IMAGE):$(VERSION) ...
docker rmi -f $(IMAGE):$(VERSION)
.PHONY: clean_build
clean:
rm -rf build/
.PHONY: clean
clean: clean_build clean_docker