I always forget how to set environment variables on a Makefile, so all commands on it are able to use them. As a bonus, this serves for a flask app. So, here is how to achieve that:
SHELL := /bin/bash # necessary to use the source command, which is not on sh, Makefile's default shell ;)
help:
@echo -e " make run - Run the development server locally."
@echo -e " make shell - Open a flask interactive shell to experiment with the app."
@echo -e " make routes - List all available routes the app."
@echo -e " make debug-server - Run the development server locally using gunicorn as the app server."
@echo -e " make clean - Removes __pycache__ files from project."
run:
set -a && source .env && set +a && flask run
shell:
set -a && source .env && set +a && flask shell
routes:
set -a && source .env && set +a && flask routes
debug-server:
set -a && source .env && set +a && gunicorn -c gunicorn_config.py my_awesome_app:app -b 127.0.0.1:5000 --log-level DEBUG
clean:
find . -name '__pycache__' | xargs rm -fr