|
| 1 | + |
| 2 | +# NOTE: This is not the most perfect makefile. |
| 3 | +# There's a few things we could do to improve performance. |
| 4 | +# But since this is new, we can strive for clarity and simplicity here. |
| 5 | +# Could use many of these suggestions: |
| 6 | +# https://docs.cloudposse.com/reference/best-practices/make-best-practices/ |
| 7 | + |
| 8 | + |
| 9 | +# On _some_ systems, make might not default to bash, which might produce |
| 10 | +# unexpected output/errors. It's assumed that all of the recipes here are written |
| 11 | +# in bash syntax. |
| 12 | +SHELL = /bin/bash |
| 13 | +.SHELLFLAGS = -e -u -o pipefail -c |
| 14 | + |
| 15 | + |
| 16 | +default: help |
| 17 | + |
| 18 | + |
| 19 | +# TODO: Add more descriptions to makefile targets |
| 20 | +.PHONY: help |
| 21 | +help: |
| 22 | + @echo -e "\nThese are some useful commands to work with this project." |
| 23 | + @echo -e "Please refer to the README.md for more details.\n" |
| 24 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' |
| 25 | + @echo -e "\nFor more information, please read the Makefile\n" |
| 26 | + |
| 27 | + |
| 28 | +.env: |
| 29 | + @echo "Missing '.env' file. Creating one using 'env.example' as a template" |
| 30 | + @cp env.example .env |
| 31 | + @echo "Please open the '.env' file and adjust to your local setup!" |
| 32 | + |
| 33 | + |
| 34 | +.venv: ## Creates a virtualenv at `./.venv` |
| 35 | + @python -m venv .venv |
| 36 | + |
| 37 | + |
| 38 | +.PHONY: setup |
| 39 | +setup: .env .venv requirements.txt.log requirements-mysql.txt.log requirements-postgresql.txt.log ## Sets up the project (installs dependencies etc.) |
| 40 | + |
| 41 | + |
| 42 | +requirements.txt.log: requirements.txt |
| 43 | + @pip install -r requirements.txt | tee .requirements.txt.tmp.log |
| 44 | + @mv .requirements.txt.tmp.log requirements.txt.log |
| 45 | + |
| 46 | +requirements-mysql.txt.log: .env requirements-mysql.txt |
| 47 | + @(grep '^W2_DATABASE_ENGINE' .env | grep 'mysql' > /dev/null && pip install -r requirements-mysql.txt || echo "Not using MySQL") | tee .requirements-mysql.txt.tmp.log |
| 48 | + @mv .requirements-mysql.txt.tmp.log requirements-mysql.txt.log |
| 49 | + |
| 50 | +requirements-postgresql.txt.log: .env requirements-postgresql.txt |
| 51 | + @(grep '^W2_DATABASE_ENGINE' .env | grep 'postgresql' > /dev/null && pip install -r requirements-postgresql.txt || echo "Not using PostgreSQL") | tee .requirements-postgresql.txt.tmp.log |
| 52 | + @mv .requirements-postgresql.txt.tmp.log requirements-postgresql.txt.log |
| 53 | + |
| 54 | + |
| 55 | +.PHONY: test |
| 56 | +test: setup ## Runs the unit tests |
| 57 | + @. .venv/bin/activate |
| 58 | + @./manage.py test |
| 59 | + |
| 60 | + |
| 61 | +.PHONY: migrate |
| 62 | +migrate: setup ## Runs the migrate Django management command |
| 63 | + @. .venv/bin/activate |
| 64 | + @./manage.py migrate |
| 65 | + |
| 66 | + |
| 67 | +.PHONY: load_fake_data |
| 68 | +load_fake_data: setup ## Loads up fake data using custom Django management command |
| 69 | + @. .venv/bin/activate |
| 70 | + @./manage.py load_fake_data --full --reset |
| 71 | + |
| 72 | +.PHONY: run |
| 73 | +run: setup ## Runs the Django development server |
| 74 | + @. .venv/bin/activate |
| 75 | + @./manage.py runserver |
| 76 | + |
| 77 | + |
| 78 | +.PHONY: clean |
| 79 | +clean: ## Removes cached python files and virtualenv |
| 80 | + @echo "Deleting '__pycache__/' directories" |
| 81 | + @find . -name "__pycache__" -exec rm -rf {} \+ |
| 82 | + @echo "Deleting the virtualenv ('./.venv/')" |
| 83 | + @rm -rf .venv |
| 84 | + |
| 85 | + |
| 86 | +.PHONY: docker/build |
| 87 | +docker/build: ## Builds a Docker image and tags |
| 88 | + docker build -t wasa2il . |
| 89 | + |
0 commit comments