Created
April 3, 2017 15:31
-
-
Save coffeemancy/3f62b5dba234abdc33d4f5a2008bd961 to your computer and use it in GitHub Desktop.
python package boilerplate
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
function _error() { | |
>&2 printf "\e[31mERROR: $@\e[00m\n" | |
exit 1 | |
} | |
function _note() { | |
printf "\e[32m\n[ $@ ]\n---------------------\e[00m\n" | |
} | |
function _warn() { | |
printf "\e[33mWARNING: $@\e[00m\n" | |
} | |
function _check_history_updated() { | |
set +x | |
_note "Checking HISTORY has been updated" | |
local history_file=HISTORY.rst | |
local diffs=$(git --no-pager diff --shortstat origin/master $history_file) | |
if ! echo $diffs | grep 'changed'; then | |
_error "$history_file must be updated to reflect changes!" | |
else | |
echo "$history_file is updated." | |
fi | |
set -x | |
} | |
function _usage() { | |
echo "Usage: ./build.sh TARGET" | |
echo "Runs target (test, release)." | |
echo | |
echo " TARGET action to perform (e.g. test, release)" | |
echo | |
echo " -h, --help print this usage" | |
} | |
function _pip_install(){ | |
# install requirements with pip | |
local req_type=$1 | |
_note "Pip Installing" | |
set -x | |
pip install --upgrade pip setuptools wheel | |
pip install -e .\[$req_type\] | |
set +x | |
} | |
function _pytest() { | |
local args=$@ | |
py.test -svv -p no:sugar --maxfail=1 $args | |
} | |
function _run_target() { | |
# run specified target with arguments | |
local target=$1 | |
shift | |
local args=$@ | |
# prevent issue using new version of coverage | |
rm -f .coverage | |
_pip_install "test" | |
case "$target" in | |
release) | |
_pip_install "release" | |
_note "Running Release" | |
set -x | |
fullrelease --no-input | |
set +x ;; | |
test*) | |
_note "Running Test" | |
set -x | |
flake8 | |
pydocstyle | |
_check_history_updated | |
_pytest $args | |
set +x | |
# continue testing below cases, to handle specific tests | |
;;& | |
test) | |
# run both | |
_run_functional_tests "functional" ;; | |
*) | |
_error "No target found for $target!" ;; | |
esac | |
} | |
if [ $# -lt 1 ]; then | |
_usage | |
_error "Target must be specified!" | |
elif [ $1 == '-h' ] || [ $1 == '--help' ]; then | |
_usage | |
else | |
_run_target $@ | |
fi | |
This file contains hidden or 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
[coverage:run] | |
branch=True | |
omit=setup.py | |
[flake8] | |
exclude=docs/* | |
[metadata] | |
description-file=README.rst | |
[pydocstyle] | |
match=(?!__init__)(?!test_)(?!conf).*\.py | |
[pytest] | |
addopts=--cov=foo --cov-report=term-missing --durations=3 --ff --flakes --mccabe --strict --maxfail=5 -ra --tb=long | |
mccabe-complexity=15 | |
pep8ignore=docs/* ALL | |
[pytest:flake8] | |
exclude=docs/* | |
[tool:pytest] | |
addopts=--cov=foo --cov-report=term-missing --durations=3 --ff --flakes --mccabe --strict --maxfail=5 -ra --tb=long | |
mccabe-complexity=15 | |
pep8ignore=docs/* ALL |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
"""Some package.""" | |
# batteries included | |
from __future__ import absolute_import | |
from setuptools import find_packages, setup | |
doc_requirements = [...] | |
install_requirements = [...] | |
release_requirements = [ | |
'zest.releaser[recommended]>=6.6.5,<6.7'] | |
test_requirements = [ | |
..., | |
'coverage>=3,<4', | |
'flake8>=3.3.0,<4', | |
'pydocstyle>=1.1.1,<2', | |
'pytest>=2.9.2,<3', | |
'pytest-cov>=2.4.0,<3', | |
'pytest-flakes>=1.0.1,<2', | |
'pytest-mccabe>=0.0.1,<2', | |
'pytest-mock>=0.11.0,<1'] | |
dev_requirements = ( | |
doc_requirements + test_requirements + release_requirements) | |
entry_points = { | |
'console_scripts': ['foo=foo.views.cli:cli']} | |
scripts = ['bin/foo-complete'] | |
setup(name='foo', | |
version='0.1.0.dev0', | |
description='Foo', | |
author='Who', | |
author_email='[email protected]', | |
classifiers=[ | |
'Development Status :: 4 - Beta', | |
'Intended Audience :: Someone', | |
'License :: Other/Proprietary License', | |
'Natural Language :: English', | |
'Operating System :: MacOS :: MacOS X', | |
'Operating System :: POSIX :: Linux', | |
'Programming Language :: Python :: 2', | |
'Programming Language :: Python :: 2.7', | |
], | |
entry_points=entry_points, | |
keywords=['foo', 'bar'], | |
url='https://github.com/foo/foo', | |
packages=find_packages(), | |
package_dir={'foo': 'foo'}, | |
package_data={'foo': ['templates/*']}, | |
extras_require={ | |
'dev': dev_requirements, | |
'doc': doc_requirements, | |
'release': release_requirements, | |
'test': test_requirements}, | |
install_requires=install_requirements, | |
scripts=scripts, | |
tests_require=test_requirements, | |
test_suite='tests') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment