Last active
September 30, 2015 12:31
-
-
Save chaosmail/7d67a998922d3d07686e to your computer and use it in GitHub Desktop.
Python Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Project Setup | |
pkg_name = MoreSpaceEducation | |
venv_dir = .venv | |
src_dir = $(pkg_name) | |
python = python3.4 | |
# Declare the tools | |
pkgm = pip | |
venv = virtualenv --no-site-packages --distribute -p /usr/bin/$(python) | |
test = pytest | |
lint = pep8 | |
# Declare the commands | |
venv_cmd = $(venv) | |
pkgm_cmd = $(python) -m $(pkgm) | |
test_cmd = $(python) -m $(test) | |
lint_cmd = $(python) -m $(lint) | |
# Install the application | |
.PHONY: install | |
install: | |
$(pkgm_cmd) install $(test) | |
$(pkgm_cmd) install $(lint) | |
$(pkgm_cmd) install -r requirements.txt | |
$(pkgm_cmd) install -e . | |
# Run the test suite | |
.PHONY: test | |
test: | |
$(test_cmd) $(pkg_name) | |
# Lint the coding guidelines | |
.PHONY: lint | |
lint: | |
$(lint_cmd) --max-line-length=120 $(pkg_name) | |
# Clean the directory | |
.PHONY: clean | |
clean: | |
py3clean $(src_dir) | |
rm -rf $(pkg_name).egg-info | |
rm -rf dist | |
rm -rf $(venv_dir) | |
find $(src_dir) -type d -name 'node_modules' -exec rm -rf {} + | |
find $(src_dir) -type d -name 'bower_components' -exec rm -rf {} + | |
# Write the requirements to file | |
.PHONY: freeze | |
freeze: | |
$(pkgm_cmd) freeze > requirements.txt | |
# Create the virtual environment | |
.PHONY: venv | |
venv: | |
test -d $(venv_dir) || $(venv_cmd) $(venv_dir) | |
@echo "To activate the virtual environment run following command:" | |
@echo "source $(venv_dir)/bin/activate" | |
@echo "Copying command to clipboard" | |
echo "source $(venv_dir)/bin/activate" | xclip -sel clip | |
# Self-update the Makefile | |
MAKE_PATH = https://gist.githubusercontent.com/chaosmail/7d67a998922d3d07686e/raw$(date +%s) | |
.PHONY: self-update | |
self-update: | |
curl -s -o Makefile.bak $(MAKE_PATH) | |
sed -i '2s/.*/pkg_name = ${pkg_name}/' Makefile.bak | |
rm Makefile | |
mv Makefile.bak Makefile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment