forked from smari/wasa2il
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMakefile
117 lines (82 loc) · 4.04 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
# NOTE: This is not the most perfect makefile.
# There's a few things we could do to improve performance.
# But since this is new, we can strive for clarity and simplicity here.
# Could use many of these suggestions:
# https://docs.cloudposse.com/reference/best-practices/make-best-practices/
# On _some_ systems, make might not default to bash, which might produce
# unexpected output/errors. It's assumed that all of the recipes here are written
# in bash syntax.
SHELL = /bin/bash
.SHELLFLAGS = -e -u -o pipefail -c
default: help
# TODO: Add more descriptions to makefile targets
.PHONY: help
help:
@echo -e "\nThese are some useful commands to work with this project."
@echo -e "Please refer to the README.md for more details.\n"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo -e "\nFor more information, please read the Makefile\n"
.env:
@echo "Missing '.env' file. Creating one using 'env.example' as a template"
@cp env.example .env
@echo "Please open the '.env' file and adjust to your local setup!"
@exit 1
.venv: .env ## Creates a virtualenv at `./.venv`
@python -m venv .venv
.PHONY: setup
setup: .env .venv requirements.txt.log requirements-mysql.txt.log requirements-postgresql.txt.log ## Sets up the project (installs dependencies etc.)
requirements.txt.log: .venv requirements.txt.freeze
@. .venv/bin/activate && pip install -r requirements.txt.freeze | tee .requirements.txt.tmp.log
@mv .requirements.txt.tmp.log requirements.txt.log
requirements-mysql.txt.log: .env .venv requirements-mysql.txt.freeze
ifeq ($(shell grep '^W2_DATABASE_ENGINE' .env 2>/dev/null | grep 'mysql' > /dev/null && echo yes || echo no), yes)
@. .venv/bin/activate && pip install -r requirements-mysql.txt.freeze | tee .requirements-mysql.txt.tmp.log
else
@echo "Not using MySQL" | tee .requirements-mysql.txt.tmp.log
endif
@mv .requirements-mysql.txt.tmp.log requirements-mysql.txt.log
requirements-postgresql.txt.log: .env .venv requirements-postgresql.txt.freeze
ifeq ($(shell grep '^W2_DATABASE_ENGINE' .env 2>/dev/null | grep 'psyco' > /dev/null && echo yes || echo no), yes)
@. .venv/bin/activate && pip install -r requirements-postgresql.txt.freeze | tee .requirements-postgresql.txt.tmp.log
else
@echo "Not using PostgreSQL" | tee .requirements-postgresql.txt.tmp.log
endif
@mv .requirements-postgresql.txt.tmp.log requirements-postgresql.txt.log
.PHONY: freeze-dependencies
freeze-dependencies:
@. .venv/bin/activate && pip freeze | grep -v 'mysqlclient' > requirements.txt.freeze
ifeq ($(shell grep '^W2_DATABASE_ENGINE' .env 2>/dev/null | grep 'mysql' > /dev/null && echo yes || echo no), yes)
@. .venv/bin/activate && pip freeze | grep 'mysqlclient' > requirements-mysql.txt.freeze
endif
ifeq ($(shell grep '^W2_DATABASE_ENGINE' .env 2>/dev/null | grep 'psyco' > /dev/null && echo yes || echo no), yes)
@ .venv/bin/activate && pip freeze | grep 'psycopg' > requirements-postgresql.txt.freeze
endif
.PHONY: update-dependencies
update-dependencies:
@rm -rf .venv/
@make .venv
@. .venv/bin/activate && pip install -r requirements.txt
@make freeze-dependencies
.PHONY: test
test: setup ## Runs the unit tests
@. .venv/bin/activate && ./manage.py test
.PHONY: migrate
migrate: setup ## Runs the migrate Django management command
@. .venv/bin/activate && ./manage.py migrate
.PHONY: load_fake_data
load_fake_data: setup ## Loads up fake data using custom Django management command
@. .venv/bin/activate && ./manage.py load_fake_data --full --reset
.PHONY: run
run: setup ## Runs the Django development server
@. .venv/bin/activate && ./manage.py runserver
.PHONY: clean
clean: ## Removes cached python files and virtualenv
@echo "Deleting '__pycache__/' directories"
@find . -name "__pycache__" -exec rm -rf {} \+
@echo "Deleting requirement log files"
@rm requirements*.log 2>/dev/null || true
@echo "Deleting the virtualenv ('./.venv/')"
@rm -rf .venv 2>/dev/null || true
.PHONY: docker/build
docker/build: ## Builds a Docker image and tags
docker build -t wasa2il .