Skip to content

Instantly share code, notes, and snippets.

@alejandrobernardis
Last active December 15, 2015 08:39
Show Gist options
  • Select an option

  • Save alejandrobernardis/5232089 to your computer and use it in GitHub Desktop.

Select an option

Save alejandrobernardis/5232089 to your computer and use it in GitHub Desktop.
Py | Makefile
# Author: Alejandro M. Bernardis
# Email: alejandro.m.bernardis at gmail.com
# Created: 2013/03/23, 17:30
# Copyright (c) 2013 Asumi Kamikaze, Inc.
# Copyright (c) 2013 The Octopus Apps, Inc.
# Licensed under the GPL License, Version 2.0 (the "License")
# Configuration
# =============
LIB = $(CURDIR)/lib
ENV = $(CURDIR)/.env
BIN = $(ENV)/bin
PIP = $(BIN)/pip
PYTHON = $(BIN)/python
PYTHON_REQUIREMENTS = $(CURDIR)/requirements.txt
PYTHON_REQUIREMENTS_EXTEND = $(CURDIR)/requirements-extend.txt
VIRTUALENV = /usr/local/bin/virtualenv
TOX = /usr/local/bin/tox
HG = /usr/local/bin/hg
HR = "--------------------------------------------------------------------------------"
DONE = \033[32mDONE!\033[39m
# Helpers
# =======
.PHONY: help init clean lint test doc pep8 flake8 pytest nosetests delete reset download force-download env push
help:
@echo "\n* Usage:"
@echo " make {init|clean|lint|test|doc}"
@echo "\n- Especial methods:"
@echo " - lint: \`pep8\` or \`flake8\` (d)"
@echo " - test: \`tox\` or \`pytest\` or \`nosetests\` (d)"
@echo "\n- Dangerous methods:"
@echo " - \`delete\`: remove all components."
@echo " - \`reset\`: remove all components and restart project."
@echo " - \`force-download\`: download again all dependencies.\n"
_exists_env:
@if [ -d $(ENV) ]; then \
echo '\033[31mERROR: The virtual enviroment already exists.\033[39m' && exit 1; fi;
_not_exists_env:
@if [ ! -d $(ENV) ]; then \
echo '\033[31mERROR: The virtual enviroment not exists.\033[39m' && exit 1; fi;
# Main
# ====
init: download
@echo "\n* Creating directories...\n$(HR)"
@printf "Removing directories... "
@rm -fR $(CURDIR)/{build,deploy,bin,doc,src,tests}
@echo "done."
@printf "Creating directories... "
@mkdir -p $(CURDIR)/{bin,doc,src/{admin,public,tasks},tests}
@echo "done."
@printf "Creating files... "
@touch $(CURDIR)/src/settings.py $(CURDIR)/src/main.py
@echo "done."
@echo "$(DONE)"
download: env
@echo "\n* Downloading dependencies...\n$(HR)"
@$(PIP) install -r $(PYTHON_REQUIREMENTS)
@if [ -f $(PYTHON_REQUIREMENTS_EXTEND) ]; then \
$(PIP) install -r $(PYTHON_REQUIREMENTS_EXTEND); fi;
@rm -f $(LIB)
@ln -s $(ENV)/lib/python2.7/site-packages/ $(LIB)
@echo "$(DONE)"
env: _exists_env
@echo "\n* Creating environment...\n$(HR)"
@rm -fR $(ENV)
@$(VIRTUALENV) --no-site-packages $(ENV)
@echo "$(DONE)"
# Dangerous
# =========
reset: delete
@make init
delete:
@echo "\n* Removing the project...\n$(HR)"
@printf "Removing directories... "
@rm -fR $(CURDIR)/{.env,.tox,lib,build,deploy,bin,doc,src,tests}
@echo "done."
@echo "$(DONE)"
force-download:
@rm -fR $(ENV) && make download
# Tools
# =====
clean:
@echo "\n* Cleaning the project...\n$(HR)"
@printf "Removing files py[co]... "
@find . -name '*.pyc' -exec rm -f {} +
@find . -name '*.pyo' -exec rm -f {} +
@echo "done."
@printf "Removing directories... "
@rm -fR $(CURDIR)/{.tox,build,deploy,doc}
@echo "done."
@printf "Creating directories... "
@mkdir -p $(CURDIR)/doc
@echo "done."
@echo "$(DONE)"
lint: flake8
pep8: _not_exists_env
@echo "\n* Checking syntax...\n$(HR)"
@$(BIN)/pep8 $(CURDIR)/src $(CURDIR)/tests
@echo "$(DONE)"
flake8: _not_exists_env
@echo "\n* Checking syntax...\n$(HR)"
@$(BIN)/flake8 $(CURDIR)/src $(CURDIR)/tests
@echo "$(DONE)"
test: nosetests
tox: lint
@echo "\n* Checking code...\n$(HR)"
@$(TOX) -c $(CURDIR)/tox.ini
@echo "$(DONE)"
pytest: lint
@echo "\n* Checking code...\n$(HR)"
@$(BIN)/py.test $(CURDIR)/tests
@echo "$(DONE)"
nosetests: lint
@echo "\n* Checking code...\n$(HR)"
@$(BIN)/nosetests $(CURDIR)/tests
@echo "$(DONE)"
doc: _not_exists_env
@echo "\n* Creating documentation...\n$(HR)"
@echo "$(DONE)"
# Undocumented
# ============
push: delete
@echo "\n* Updating remote repository...\n$(HR)"
@$(HG) status
@$(HG) commit -m 'Python // Fixes'
@$(HG) push
@echo "$(DONE)"
include tox.ini, setup.py
recursive-include tests *
http://pypi.python.org/packages/source/f/flake8/flake8-2.0.tar.gz
http://pypi.python.org/packages/source/p/pytest/pytest-2.3.4.zip
http://pypi.python.org/packages/source/n/nose/nose-1.2.1.tar.gz
http://pypi.python.org/packages/source/t/tox/tox-1.4.3.tar.gz
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 Asumi Kamikaze Inc.
# Copyright (c) 2013 The Octopus Apps Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# Author: Alejandro M. Bernardis
# Email: alejandro.m.bernardis at gmail.com
# Created: 2013/03/25 00:46
from distutils.core import setup
setup(
name='Project',
version='1.0',
license='GPLv2',
description='Build Tools',
author='Alejandro M. Bernardis',
author_email='alejandro.m.bernardis@gmail.com',
url='https://bitbucket.org/alejandrobernardis/com-ak-experiments',
packages=[],
install_requires=[],
tests_require=[],
scripts=[],
)
[tox]
envlist=
[testenv]
deps=nose
commands=nosetests tests
[pep8]
max-line-length=160
[flake8]
max-line-length=160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment