Skip to content

Instantly share code, notes, and snippets.

@mintyPT
Last active February 12, 2021 13:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mintyPT/0f10875c14484ed923c28a388d8e9330 to your computer and use it in GitHub Desktop.
Save mintyPT/0f10875c14484ed923c28a388d8e9330 to your computer and use it in GitHub Desktop.
Example of a Makefile to work with django
# ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
# SETUP
# ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
.PHONY: help activate install flake8 isort black check virtualenv-path runserver runserver_plus migrations migrate shell shell_plus makemessages compilemessages collectstatic createsuperuser reset_db startapp clear_cache services
YELLOW := "\e[1;33m"
NC := "\e[0m"
INFO := @bash -c 'printf $(YELLOW); echo "=> $$1"; printf $(NC)' MESSAGE
export ENV?= dev
help: ## [help] Show this help
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
# ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
# PYTHON RELATED COMMANDS
# ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
activate: ## [python] Activate python virtual env
@ poetry shell
install: ## [python] Install python packages with poetry
@ poetry install
flake8: ## [python] Run flake8 (linter)
@ poetry run flake8
isort: ## [python] Run isort (import sorter)
@ poetry run isort .
black: ## [python] Run black (code formatter)
@ poetry run black .
check: isort black flake8 ## [python] Run isort, black and flake8
virtualenv-path: ## [python] Show virtualenv path
@ poetry env info --path
# ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
# DJANGO RELATED COMMANDS
# ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
runserver: ## [django] Run server (vanilla version)
@ poetry run python manage.py runserver 127.0.0.1:8001
runserver_plus: ## [django] Run server (django-extensions runserver_plus version)
@ poetry run python manage.py runserver_plus 127.0.0.1:8001
migrations: ## [django] Run makemigrations
@ poetry run python manage.py makemigrations
migrate: ## [django] Run migrate
@ poetry run python manage.py migrate
shell: ## [django] Run shell
@ poetry run python manage.py shell
shell_plus: ## [django] Run shell_plus with ipython
@ poetry run python manage.py shell_plus --ipython
makemessages: ## [django] Run makemessages
@ poetry run python ./manage.py makemessages -l en
compilemessages: ## [django] Run compilemessages
@ poetry run python ./manage.py compilemessages -l en
collectstatic: ## [django] Run collectstatic
@ poetry run python ./manage.py collectstatic --no-input
createsuperuser: ## [django] Create a superuser
@ poetry run python manage.py createsuperuser --email admin@admin.com
reset_db: ## [django] Run reset_db
@ poetry run python manage.py reset_db
startapp: ## [django] Run startapp
@ mkdir -p ./apps/$(name)
@ poetry run python manage.py startapp $(name) ./apps/$(name)
clear_cache: ## [django] Run clear_cache
@ poetry run python ./manage.py clear_cache
# ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
# DOCKER-COMPOSE RELATED COMMANDS
# ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
services: ## [docker] Launch postgres and redis with docker-compose
docker-compose up db redis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment