Skip to content

Instantly share code, notes, and snippets.

@darthwade
Last active August 29, 2015 14:05
Show Gist options
  • Save darthwade/da0ff92eeae9845c5ef1 to your computer and use it in GitHub Desktop.
Save darthwade/da0ff92eeae9845c5ef1 to your computer and use it in GitHub Desktop.
Makefile for django reusable apps
PROJECT := demo
LOCAL_PATH := $(CURDIR)/src
VIRTUAL_ENV := $(CURDIR)/bin
PYTHON_PATH := $(LOCAL_PATH)
PYTHON_BIN := $(VIRTUAL_ENV)/scripts
SETTINGS := development
DJANGO_SETTINGS_MODULE = $(PROJECT).settings.$(SETTINGS)
DJANGO_POSTFIX := --settings=$(DJANGO_SETTINGS_MODULE) --pythonpath=$(PYTHON_PATH)
PRODUCTION_SETTINGS := production
DJANGO_PRODUCTION_SETTINGS_MODULE = $(PROJECT).settings.$(PRODUCTION_SETTINGS)
DJANGO_PRODUCTION_POSTFIX := --settings=$(DJANGO_PRODUCTION_SETTINGS_MODULE) --pythonpath=$(PYTHON_PATH)
TESTING_SETTINGS := testing
DJANGO_TESTING_SETTINGS_MODULE = $(PROJECT).settings.$(TESTING_SETTINGS)
DJANGO_TESTING_POSTFIX := --settings=$(DJANGO_TESTING_SETTINGS_MODULE) --pythonpath=$(PYTHON_PATH)
.PHONY: help clean bootstrap setup_virtualenv install_deps show_deps show_packages showenv register sdist upload collectstatic coverage runserver_unsafe test
.DEFAULT:
@$(PYTHON_BIN)/django-admin.py $@ $(FLAGS) $(DJANGO_POSTFIX)
help:
@echo "Please use 'make <target>' where <target> is one of"
@echo " clean to clean project repository"
@echo " bootstrap to bootstrap project, sets up a virtualenv and installs all deps"
@echo " setup_virtualenv to setup virtualenv"
@echo " install_deps to install PIP deps"
@echo " show_deps to show PIP deps"
@echo " show_packages to show installed PIP packages"
@echo " show_env to show some relevant environment variables"
@echo " register to register package on PyPI"
@echo " sdist to create source distribution"
@echo " upload to upload distribution to PyPI"
@echo " <django_command> to run django management command (e.g. 'make shell' or 'make compilemessages')"
clean:
@-find . -name "*.pyc" -print0 | xargs -0 rm -rf
@-find . -name "*.pyo" -print0 | xargs -0 rm -rf
@-find . -name "*.egg-info" -print0 | xargs -0 rm -rf
@-rm -rf htmlcov
@-rm -rf .coverage
@-rm -rf build
@-rm -rf dist
@-rm -rf docs/_build
bootstrap: setup_virtualenv install_deps
setup_virtualenv:
@virtualenv --no-site-packages $(VIRTUAL_ENV)
@echo $(VIRTUAL_ENV)
install_deps:
@$(PYTHON_BIN)/pip install -r requirements/$(SETTINGS).txt
show_deps:
@echo 'BASE DEPENDENCIES:'
@echo '=================='
@cat $(CURDIR)/requirements/base.txt
@echo 'DEVELOPMENT DEPENDENCIES:'
@echo '========================='
@cat $(CURDIR)/requirements/$(SETTINGS).txt
@echo 'PRODUCTION DEPENDENCIES:'
@echo '========================'
@cat $(CURDIR)/requirements/$(PRODUCTION_SETTINGS).txt
@echo 'TESTING DEPENDENCIES:'
@echo '====================='
@cat $(CURDIR)/requirements/$(TESTING_SETTINGS).txt
show_packages:
@$(PYTHON_BIN)/pip freeze
show_env:
@echo 'Environment:'
@echo '============'
@echo 'PROJECT:' $(PROJECT)
@echo '------------'
@echo 'PYTHON_PATH:' $(PYTHON_PATH)
@echo '------------'
@$(PYTHON_BIN)/python -c "import sys; print 'PYTHON VERSION:', sys.version"
@echo '------------'
@echo 'VIRTUAL_ENV:' $(VIRTUAL_ENV)
@echo '------------'
@echo 'DJANGO_SETTINGS_MODULE:' $(DJANGO_SETTINGS_MODULE)
@echo '------------'
@echo 'DJANGO_LOCAL_SETTINGS_MODULE:' $(DJANGO_LOCAL_SETTINGS_MODULE)
@echo '------------'
@echo 'DJANGO_TESTING_SETTINGS_MODULE:' $(DJANGO_TESTING_SETTINGS_MODULE)
@echo '------------'
@$(PYTHON_BIN)/python -c "import sys; print 'PYTHON SYS.PATH:', sys.path"
@echo '------------'
@echo 'PATH:' $(PATH)
@echo '------------'
register:
@$(PYTHON_BIN)/python setup.py register
sdist:
@$(PYTHON_BIN)/python setup.py sdist
upload:
@$(PYTHON_BIN)/python setup.py sdist upload
# TODO
collectstatic:
@-mkdir -p .$(LOCAL_PATH)/static
@$(PYTHON_BIN)/django-admin.py collectstatic -c --noinput $(DJANGO_POSTFIX)
# TODO
test: clean
@$(PYTHON_BIN)/django-admin.py test $(APP) $(DJANGO_TESTING_POSTFIX)
# TODO
coverage:
@$(PYTHON_BIN)/coverage run --source="$(PYTHON_PATH)/" $(PYTHON_BIN)/django-admin.py test $(APP) $(DJANGO_TESTING_POSTFIX)
@$(PYTHON_BIN)/coverage html --include="$(LOCAL_PATH)/*" --omit="*/admin.py,*/test*"
# TODO
runserver_unsafe:
@$(PYTHON_BIN)/django-admin.py runserver --insecure $(DJANGO_LOCAL_POSTFIX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment