Skip to content

Instantly share code, notes, and snippets.

@allanlewis
Last active August 18, 2017 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allanlewis/1211989ef4a397c9f385086f0abd5837 to your computer and use it in GitHub Desktop.
Save allanlewis/1211989ef4a397c9f385086f0abd5837 to your computer and use it in GitHub Desktop.
A Makefile for managing Python requirements in a sane way without extra Python tools.
python ?= python3
pip := pip --disable-pip-version-check
export PATH := .env/bin:$(PATH)
#######################
# Python environments #
#######################
.env:
$(python) -m venv .env
prod-env: requirements/prod.in
test-env: requirements/test.in | prod-env
prod-env test-env: | .env
$(pip) install -r $<
.PHONY: prod-env test-env
#######################
# Python requirements #
#######################
requirements/prod.txt: requirements/prod.in | clean-env prod-env
requirements/test.txt: requirements/test.in | test-env
requirements/prod.txt requirements/test.txt:
$(pip) freeze -r $@ > $@
#########
# Clean #
#########
clean-all: clean-env clean-python
clean-env:
rm -rf .env
clean-python:
find -name '__pycache__' -type d -prune | xargs rm -rf
find -name '*.pyc' -type f -delete
.PHONY: clean-all clean-env clean-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment