Skip to content

Instantly share code, notes, and snippets.

@chaosmail
Last active September 30, 2015 12:31
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 chaosmail/7d67a998922d3d07686e to your computer and use it in GitHub Desktop.
Save chaosmail/7d67a998922d3d07686e to your computer and use it in GitHub Desktop.
Python Makefile
# 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