-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
183 lines (125 loc) · 3.81 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
# ENV defaults to local (so that requirements/local.txt are installed), but can be overridden
# (e.g. ENV=production make setup).
ENV ?= local
# PYTHON specifies the python binary to use when creating virtualenv
PYTHON ?= python3.9
# Editor can be defined globally but defaults to nano
EDITOR ?= nano
# By default we open the editor after copying settings, but can be overridden
# (e.g. EDIT_SETTINGS=no make settings).
EDIT_SETTINGS ?= yes
# Project name
PROJECT_NAME ?= app
# Get root dir and project dir
PROJECT_ROOT ?= $(CURDIR)
SITE_ROOT ?= $(PROJECT_ROOT)/$(PROJECT_NAME)
CUR_DIR_NAME ?= $(shell basename `pwd`)
.PHONY:
all: help
.PHONY:
help:
@echo "+------<<<< Configuration >>>>------+"
@echo ""
@echo "ENV: $(ENV)"
@echo "PYTHON: $(PYTHON)"
@echo "PROJECT_ROOT: $(PROJECT_ROOT)"
@echo "SITE_ROOT: $(SITE_ROOT)"
@echo ""
@echo "+------<<<< Tasks >>>>------+"
@echo ""
@grep --no-filename -E '^[a-zA-Z_%-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
.PHONY:
docker:
@docker-compose down
@docker-compose build
@docker-compose up -d
@docker-compose logs -f
.PHONY:
setup: ## Sets up the project in your local machine
@echo "Creating Docker images"
@docker-compose build
@echo "Running django migrations"
@make migrate
@echo "===================================================================="
@echo "SETUP SUCCEEDED"
$(PROJECT_ROOT)/.env:
@echo "Copying .env file"
@cp $(PROJECT_ROOT)/.env.example $(PROJECT_ROOT)/.env
.PHONY:
clean:
@echo "Cleaning pyc files"
@make run-python cmd='find . -name "*.pyc" -exec rm -rf {} \;'
.PHONY:
psql:
docker-compose exec postgres psql --user $(PROJECT_NAME) --dbname $(PROJECT_NAME)
.PHONY:
docker-django:
docker-compose run --rm app $(cmd)
.PHONY:
django-shell:
docker-compose run --rm app bash
.PHONY:
docker-manage:
docker-compose run --rm app ./manage.py $(cmd)
.PHONY:
shell: ## Drop into Django shell
docker-compose run --rm app ./manage.py shell
.PHONY:
makemigrations migrations: ## Generate new DB migrations
docker-compose run --rm app ./manage.py makemigrations $(cmd)
.PHONY:
migrate: ## Apply DB migrations
docker-compose run --rm app ./manage.py migrate $(cmd)
PYTHON_DOCKER_IMAGE ?= "tg-hug_app"
# NOTE:
# Do not use `docker-compose run` to avoid spawning services by the app container
.PHONY:
run-python:
@set -e ;\
if [ "`docker images|grep $(PYTHON_DOCKER_IMAGE)`" = '' ]; then \
docker-compose build app || exit $$?; \
fi; \
docker run -t --rm -v $(PROJECT_ROOT)/app:/app $(PYTHON_DOCKER_IMAGE) $(cmd)
.PHONY:
black-check:
@make run-python cmd="black --check --diff $(cmd)"
.PHONY:
black-check-all:
@make run-python cmd="black --check --diff ."
.PHONY:
black-format:
@make run-python cmd="black $(cmd)"
.PHONY:
black-format-all:
@make run-python cmd="black ."
.PHONY:
lint: black-check-all isort python-lint mypy
.PHONY:
quality: lint poetry-check ## Run quality checks
.PHONY:
fmt: black-format-all isort-fix ## Format Python Files
.PHONY:
python-lint:
@echo "Running pylint"
@make run-python cmd="pylint"
.PHONY:
mypy:
@echo "Checking types"
@make run-python cmd="mypy --show-error-codes"
.PHONY:
isort:
@echo "Checking imports with isort"
@make run-python cmd='isort --check-only -p app --diff'
.PHONY:
isort-fix:
@echo "Fixing imports with isort"
@make run-python cmd='isort .'
.PHONY:
coverage: ## Runs python test coverage calculation
@echo "Running automatic code coverage check"
@docker-compose run --rm app pytest --cov=. --cov-report html --cov-report xml --cov-report term-missing
.PHONY:
test: ## Run python test suit
@echo "Running automatic tests"
@docker-compose run --rm app py.test