-
Notifications
You must be signed in to change notification settings - Fork 150
/
Makefile
165 lines (130 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
lessopts="--tabs=4 --quit-if-one-screen --RAW-CONTROL-CHARS --no-init"
ENV_DIR := .venv
PIP_BIN := $(ENV_DIR)/bin/pip
PIP_COMPILE := $(ENV_DIR)/bin/pip-compile
APP_BIN := $(ENV_DIR)/bin/promgen
CELERY_BIN := $(ENV_DIR)/bin/celery
SPHINX := $(ENV_DIR)/bin/sphinx-build
RUFF_BIN := $(ENV_DIR)/bin/ruff
DOCKER_TAG := promgen:local
SYSTEM_PYTHON ?= python3.9
# Help 'function' taken from
# https://gist.github.com/prwhite/8168133#gistcomment-2278355
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM=20
.PHONY: help
## Show help
help:
@echo ''
@echo 'Usage:'
@echo ' $(YELLOW)make$(RESET) $(GREEN)<target>$(RESET)'
@echo ''
@echo 'Targets:'
@awk '/^[\%a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " $(YELLOW)%-$(TARGET_MAX_CHAR_NUM)s$(RESET) $(GREEN)%s$(RESET)\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
###############################################################################
### Pip Tasks
###############################################################################
$(APP_BIN): $(PIP_BIN)
$(PIP_BIN) install -e .[dev,mysql] -r docker/requirements.txt
$(PIP_BIN):
$(SYSTEM_PYTHON) -m venv $(ENV_DIR)
$(PIP_BIN) install --upgrade pip wheel
.PHONY: list
list: $(PIP_BIN)
$(PIP_BIN) list --outdated
$(PIP_COMPILE): $(PIP_BIN)
$(PIP_BIN) install pip-tools
docker/requirements.txt: $(PIP_COMPILE) pyproject.toml docker/requirements.in
$(PIP_COMPILE) --output-file docker/requirements.txt pyproject.toml docker/requirements.in --no-emit-index-url
.PHONY: pip
## Reinstall with pip
pip: docker/requirements.txt
$(PIP_BIN) install --upgrade pip wheel
$(PIP_BIN) install -e .[dev,mysql] -r docker/requirements.txt
.PHONY: compile
## Pip: Compile requirements
compile: docker/requirements.txt
###############################################################################
### Other Tasks
###############################################################################
.PHONY: build
## Docker: Build container
build:
docker build . --tag $(DOCKER_TAG)
.PHONY: demo
## Docker: Run a demo via docker-compose
demo:
docker-compose up
#### Django Commands
.PHONY: test
test: $(APP_BIN)
## Django: Run tests
$(APP_BIN) collectstatic --noinput
$(APP_BIN) test -v 2 --buffer
.PHONY: bootstrap
## Django: Bootstrap install
bootstrap: $(APP_BIN)
$(APP_BIN) bootstrap
$(APP_BIN) migrate
$(APP_BIN) check
.PHONY: check
## Django: Run Django checks
check: $(APP_BIN)
$(APP_BIN) check
.PHONY: migrate
## Django: Run migrations
migrate: $(APP_BIN)
$(APP_BIN) migrate
.PHONY: run
## Django: Run development server
run: migrate
ifneq ($(DEBUG),1)
$(APP_BIN) collectstatic --noinput
endif
$(APP_BIN) runserver
.PHONY: shell
## Django: Development shell
shell: $(APP_BIN)
@echo opening promgen shell
@$(APP_BIN) shell
dump: $(APP_BIN)
$(APP_BIN) dumpdata promgen.DefaultExporter --indent=2 --output promgen/fixtures/exporters.yaml --format=yaml
.PHONY: load
load: $(APP_BIN)
$(APP_BIN) loaddata exporters
#### Documentation
$(SPHINX): $(PIP_BIN)
$(PIP_BIN) install -e .[dev,docs]
.PHONY: docs
## Sphinx: Build documentation
docs: $(SPHINX)
$(SPHINX) -avb html docs dist/html
$(RUFF_BIN): $(PIP_BIN)
$(PIP_BIN) install ruff
.PHONY: format
format: $(RUFF_BIN)
$(RUFF_BIN) check promgen --fix
$(RUFF_BIN) format promgen
#### Other assorted commands
.PHONY: clean
## Clean our repo
clean:
@echo Removing venv
@rm -rf .venv
@echo Clearing dist files
@rm -rf dist
.PHONY: changelog
changelog:
git log --color=always --first-parent --pretty='format:%s|%Cgreen%d%Creset' | column -ts '|' | less "$(lessopts)"