From b5668acefb0af1291b2aa6585a16aa6f4942d1bb Mon Sep 17 00:00:00 2001 From: Matthew Rankin Date: Thu, 7 Aug 2014 13:47:30 -0500 Subject: [PATCH] Closes #2 add inv tasks for PyPi deploy and test automation --- CHANGES.md | 13 +++++++++++++ requirements.txt | 15 +++++++-------- sdfascii.py | 7 +++++++ setup.cfg | 2 ++ setup.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- tasks.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 CHANGES.md create mode 100644 setup.cfg create mode 100644 tasks.py diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..8b3d3cb --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,13 @@ +# Changelog + +### develop (unreleased) + +### v0.1 (August 7, 2014) + +#### Enhancements + +- Add Travis-CI testing [#1][] +- Create invoke tasks to automate PyPi deploy [#2][] + +[#1]: https://github.com/questrail/sdfascii/issues/1 +[#2]: https://github.com/questrail/sdfascii/issues/2 diff --git a/requirements.txt b/requirements.txt index c891c13..0679c7a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,7 @@ -distribute==0.6.31 -git-remote-helpers==0.1.0 -numpy==1.7.0 -stevedore==0.7.2 -virtualenv==1.8.4 -virtualenv-clone==0.2.4 -virtualenvwrapper==3.6 -wsgiref==0.1.2 +flake8==2.2.2 +invoke==0.8.2 +mccabe==0.2.1 +nose==1.3.3 +numpy==1.8.1 +pep8==1.5.7 +pyflakes==0.8.1 diff --git a/sdfascii.py b/sdfascii.py index 5407ac9..0b03fe7 100755 --- a/sdfascii.py +++ b/sdfascii.py @@ -24,8 +24,15 @@ # Data analysis related imports import numpy as np +__version__ = '0.1' + def _strip_nonprintable(input_string): + ''' + (str) -> str + + Return input_string without nonprintable characters + ''' return input_string.split('\x00', 1)[0] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b88034e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md diff --git a/setup.py b/setup.py index e5d2405..b48db9a 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,53 @@ -from distutils.core import setup +import codecs +import os +import re + +from setuptools import setup + +here = os.path.abspath(os.path.dirname(__file__)) + + +def read(*parts): + """Read parts of a file + + Taken from pip's setup.py + intentionally *not* adding an encoding option to open + see: https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690 + """ + return codecs.open(os.path.join(here, *parts), 'r').read() + + +def find_version(*file_paths): + """Find version in source file + + Read the version number from a source file. + Code taken from pip's setup.py + """ + version_file = read(*file_paths) + # The version line must have the form: + # __version__ = 'ver' + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + +try: + import pypandoc + long_description = pypandoc.convert('README.md', 'rst') +except(IOError, ImportError): + long_description = open('README.md').read() + setup( name='sdfascii', - version='0.1.0', + version=find_version('sdfascii.py'), author='Matthew Rankin', author_email='matthew@questrail.com', py_modules=['sdfascii'], url='http://github.com/questrail/sdfascii', license='LICENSE.txt', description='Read HP SDF binary and ASCII files', + long_description=long_description, requires=['numpy (>=1.6.0)'], classifiers=[ 'Programming Language :: Python', diff --git a/tasks.py b/tasks.py new file mode 100644 index 0000000..4bbea24 --- /dev/null +++ b/tasks.py @@ -0,0 +1,43 @@ +from invoke import run, task + +TESTPYPI = "https://testpypi.python.org/pypi" + + +@task +def lint(): + """Run flake8 to lint code""" + run("python setup.py flake8") + + +@task(lint) +def test(): + """Lint, unit test, and check setup.py""" + run("nosetests") + run("python setup.py check") + + +@task() +def release(deploy=False, test=False, version=''): + """Tag release, run Travis-CI, and deploy to PyPI + """ + if test: + run("python setup.py check") + run("python setup.py register sdist upload --dry-run") + + if deploy: + run("python setup.py check") + if version: + run("git checkout master") + run("git tag -a v{ver} -m 'v{ver}'".format(ver=version)) + run("git push") + run("git push origin --tags") + run("python setup.py register sdist upload") + else: + print("* Have you updated the version in taffmat.py?") + print("* Have you updated CHANGES.md?") + print("* Have you fixed any last minute bugs?") + print("If you answered yes to all of the above questions,") + print("then run `invoke release --deploy -vX.YY` to:") + print("- Checkout master") + print("- Tag the git release with provided vX.YY version") + print("- Push the master branch and tags to repo")