From 284a7baa727bb485caab55121d006f11d0cd3c78 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Fri, 23 Dec 2016 20:58:09 -0800 Subject: [PATCH] [IMP] travis: Add PyPi deploy * Adds compatibility for auto-deploy as introduced in LasLabs/python-quality-tools#3 --- .travis.yml | 40 +++++++++++++++--------- setup.py | 89 ++++++++++++++++++++++++++++++++++++++++------------- tests.py | 34 -------------------- 3 files changed, 93 insertions(+), 70 deletions(-) delete mode 100644 tests.py diff --git a/.travis.yml b/.travis.yml index bab8517..a3fada6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,30 +1,40 @@ addons: - apt: - packages: - - expect-dev # provides unbuffer utility + apt: + packages: + - expect-dev # provides unbuffer utility language: python python: - - "2.7" + - "2.7" virtualenv: - system_site_packages: true + system_site_packages: true env: - global: - - TESTS="0" LINT_CHECK="0" DOCS="0" VERSION="0.1.0" RELEASE="0.1.0" PROJECT="Python CFSSL" BRANCH_PROD="master" BRANCH_DOC="gh-pages" - matrix: - - TESTS="1" - - DOCS="1" + global: + - VERSION="0.1.0" + - RELEASE="0.0.2" + - PROJECT="Python CFSSL" + - BRANCH_PROD="master" + - BRANCH_DOC="gh-pages" + - TESTS="0" + - LINT_CHECK="0" + - DOCS="0" + - PYPI="0" + - secure: "m5bpPi2ZU6vNchdCjGrj75NR2AWeGHTdPzpU7GIkintcaNA/wX9HPly7NsC91bZ0M3gzuY+xcJuUhKCTlHmDTnr2owP9bS21UFl6sd+WX1SfWcJibrcBdYVtqi3iJphoRnGFcPVq6KAx2s3IcitZivE++PdyLNac1gQgOzcshYcFEenVT+Q1kemPf8uC7bYZHrm75o6ukoeJXA1ydMxBk479YLtWkx6GefMJdCE4vN73SKUakuwZSgBD6s3EqntBWtf6jvFrIKnq0taGe8bSu0GMgX2BwBRrDkLzk0bKRH8B4cmb1MJ/0wCHboKculPVNNrqsYJ7tPlExUnLloPUUKXQKQHNJkaNV77fI8OrRyqu/jZW2IMsN/VgPHrzofmewM++Zd8IRugBjAJAC5BPl2nZQNn4QGoS7rDCjhG6phL+0YyM4wCdzcLBPrqJ4p1hDE6s2Hw6pSmDRie8lKHVMmxasbVUi/SP4lSUMzE/0UeRbTlWAoSA4ogIhWhOUy9P46tfzm2PhRjckx2MCH9Z4fPTWA44lK1SjwPRxBjC4o5Cj6fa4B5PRMSz+DaXyuB0uW0OB7pN9aLozkv7gKemv4GEeid8IWyHl7RwRv/OsCdLJ26+mJ/vqpei33ZxzhGHKjFxechCLa5n3SJm8jGAZicWv3xbiWyxR2SHsJH7PIw=" + matrix: + - TESTS="1" + - PYPI="1" + - DOCS="1" install: - - git clone --depth=1 https://github.com/LasLabs/python-quality-tools.git ${HOME}/python-quality-tools - - export PATH=${HOME}/python-quality-tools/travis:${PATH} - - travis_install + - git clone --depth=1 https://github.com/LasLabs/python-quality-tools.git ${HOME}/python-quality-tools + - export PATH=${HOME}/python-quality-tools/travis:${PATH} + - travis_install script: - - travis_run + - travis_run after_success: - - travis_after_success + - travis_after_success diff --git a/setup.py b/setup.py index 6a54047..21aa0de 100644 --- a/setup.py +++ b/setup.py @@ -1,42 +1,89 @@ # -*- coding: utf-8 -*- -# Copyright 2015-TODAY LasLabs Inc. +# Copyright 2016-TODAY LasLabs Inc. # License MIT (https://opensource.org/licenses/MIT). -from setuptools import setup +from setuptools import Command, setup from setuptools import find_packages -from tests import Tests +from unittest import TestLoader, TextTestRunner + +from os import environ, path + + +PROJECT = 'cfssl' +SHORT_DESC = ( + 'This library will allow you to interact with a remote CFSSL ' + 'server using Python.' +) +README_FILE = 'README.rst' + +version = environ.get('RELEASE') or environ.get('VERSION') or '0.0.0' + +if environ.get('TRAVIS_BUILD_NUMBER'): + version += 'b%s' % environ.get('TRAVIS_BUILD_NUMBER') setup_vals = { - 'name': 'cfssl', - 'version': '0.0.2', + 'name': PROJECT, 'author': 'LasLabs Inc.', 'author_email': 'support@laslabs.com', - 'description': 'This library will allow you to interact with CFSSL ' - 'using Python.', - 'url': 'https://laslabs.github.io/python-cfssl', - 'download_url': 'https://github.com/LasLabs/python-cfssl', + 'description': SHORT_DESC, + 'url': 'https://laslabs.github.io/%s' % PROJECT, + 'download_url': 'https://github.com/LasLabs/%s' % PROJECT, 'license': 'MIT', 'classifiers': [ 'Development Status :: 4 - Beta', 'Environment :: Console', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', - 'Operating System :: POSIX :: Linux', 'Programming Language :: Python', 'Topic :: Software Development :: Libraries :: Python Modules', ], + 'version': version, } -setup( - packages=find_packages(exclude=('tests')), - cmdclass={'test': Tests}, - tests_require=[ - 'mock', - ], - install_requires=[ - 'requests', - ], - **setup_vals -) +if path.exists(README_FILE): + with open(README_FILE) as fh: + setup_vals['long_description'] = fh.read() + + +install_requires = [] +if path.exists('requirements.txt'): + with open('requirements.txt') as fh: + install_requires = fh.read().splitlines() + + +class FailTestException(Exception): + """ It provides a failing build """ + pass + + +class Tests(Command): + ''' Run test & coverage, save reports as XML ''' + + user_options = [] # < For Command API compatibility + + def initialize_options(self, ): + pass + + def finalize_options(self, ): + pass + + def run(self, ): + loader = TestLoader() + tests = loader.discover('.', 'test_*.py') + t = TextTestRunner(verbosity=1) + res = t.run(tests) + if not res.wasSuccessful(): + raise FailTestException() + +if __name__ == "__main__": + setup( + packages=find_packages(exclude=('tests')), + cmdclass={'test': Tests}, + tests_require=[ + 'mock', + ], + install_requires=install_requires, + **setup_vals + ) diff --git a/tests.py b/tests.py deleted file mode 100644 index de321eb..0000000 --- a/tests.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2015-TODAY LasLabs Inc. -# License MIT (https://opensource.org/licenses/MIT). - -from setuptools import Command -from unittest import TestLoader, TextTestRunner - - -class FailTestException(Exception): - """ It provides a failing build """ - pass - - -class Tests(Command): - ''' Run test & coverage, save reports as XML ''' - - MODULE_NAMES = [ - 'cfssl', - ] - user_options = [] # < For Command API compatibility - - def initialize_options(self, ): - pass - - def finalize_options(self, ): - pass - - def run(self, ): - loader = TestLoader() - tests = loader.discover('.', 'test_*.py') - t = TextTestRunner(verbosity=1) - res = t.run(tests) - if not res.wasSuccessful(): - raise FailTestException()