diff --git a/NEWS b/NEWS index 667567a..810ad52 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ -* Version 2.0.0 (unreleased) - ** New major release: Now targets the U2FVAL REST API V2, which is not compatible with V1. +* Version 2.0.0 (released 2017-04-07) + ** New major release: Now targets the U2FVAL REST API V2, which is not + compatible with V1. * Version 1.0.1 (released 2015-10-27) ** Fix package so it installs. diff --git a/release.py b/release.py index 3743510..ac3e3fc 100644 --- a/release.py +++ b/release.py @@ -1,30 +1,109 @@ -# Copyright (C) 2014 Yubico AB +# Copyright (c) 2013 Yubico AB +# All rights reserved. # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +from __future__ import absolute_import + + +from setuptools import setup as _setup, find_packages, Command +from setuptools.command.sdist import sdist from distutils import log -from distutils.core import Command from distutils.errors import DistutilsSetupError +from datetime import date +from glob import glob import os import re -from datetime import date + +VERSION_PATTERN = re.compile(r"(?m)^__version__\s*=\s*['\"](.+)['\"]$") + +base_module = __name__.rsplit('.', 1)[0] + + +def get_version(module_name_or_file=None): + """Return the current version as defined by the given module/file.""" + + if module_name_or_file is None: + parts = base_module.split('.') + module_name_or_file = parts[0] if len(parts) > 1 else \ + find_packages(exclude=['test', 'test.*'])[0] + + if os.path.isdir(module_name_or_file): + module_name_or_file = os.path.join(module_name_or_file, '__init__.py') + + with open(module_name_or_file, 'r') as f: + match = VERSION_PATTERN.search(f.read()) + return match.group(1) + + +def setup(**kwargs): + if 'version' not in kwargs: + kwargs['version'] = get_version() + kwargs.setdefault('packages', find_packages(exclude=['test', 'test.*'])) + cmdclass = kwargs.setdefault('cmdclass', {}) + cmdclass.setdefault('release', release) + cmdclass.setdefault('build_man', build_man) + cmdclass.setdefault('sdist', custom_sdist) + return _setup(**kwargs) + + +class custom_sdist(sdist): + def run(self): + self.run_command('build_man') + + sdist.run(self) + + +class build_man(Command): + description = "create man pages from asciidoc source" + user_options = [] + boolean_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + self.cwd = os.getcwd() + self.fullname = self.distribution.get_fullname() + self.name = self.distribution.get_name() + self.version = self.distribution.get_version() + + def run(self): + if os.getcwd() != self.cwd: + raise DistutilsSetupError("Must be in package root!") + + for fname in glob(os.path.join('man', '*.adoc')): + self.announce("Converting: " + fname, log.INFO) + self.execute(os.system, + ('a2x -d manpage -f manpage "%s"' % fname,)) class release(Command): description = "create and release a new version" user_options = [ - ('keyid=', None, "GPG key to sign with"), + ('keyid', None, "GPG key to sign with"), ('skip-tests', None, "skip running the tests"), ('pypi', None, "publish to pypi"), ] @@ -54,6 +133,10 @@ def _verify_tag(self): raise DistutilsSetupError( "Tag '%s' already exists!" % self.fullname) + def _verify_not_dirty(self): + if os.system('git diff --shortstat | grep -q "."') == 0: + raise DistutilsSetupError("Git has uncommitted changes!") + def _sign(self): if os.path.isfile('dist/%s.tar.gz.asc' % self.fullname): # Signature exists from upload, re-use it: @@ -75,51 +158,26 @@ def _tag(self): tag_opts[0] = '-u ' + self.keyid self.execute(os.system, ('git tag ' + (' '.join(tag_opts)),)) - def _do_call_publish(self, cmd): - self._published = os.system(cmd) == 0 - - def _publish(self): - web_repo = os.getenv('YUBICO_GITHUB_REPO') - if web_repo and os.path.isdir(web_repo): - artifacts = [ - 'dist/%s.tar.gz' % self.fullname, - 'dist/%s.tar.gz.sig' % self.fullname - ] - cmd = '%s/publish %s %s %s' % ( - web_repo, self.name, self.version, ' '.join(artifacts)) - - self.execute(self._do_call_publish, (cmd,)) - if self._published: - self.announce("Release published! Don't forget to:", log.INFO) - self.announce("") - self.announce(" (cd %s && git push)" % web_repo, log.INFO) - self.announce("") - else: - self.warn("There was a problem publishing the release!") - else: - self.warn("YUBICO_GITHUB_REPO not set or invalid!") - self.warn("This release will not be published!") - def run(self): if os.getcwd() != self.cwd: raise DistutilsSetupError("Must be in package root!") self._verify_version() self._verify_tag() + self._verify_not_dirty() + self.run_command('check') self.execute(os.system, ('git2cl > ChangeLog',)) + self.run_command('sdist') + if not self.skip_tests: - self.run_command('check') - # Nosetests calls sys.exit(status) try: - self.run_command('nosetests') + self.run_command('test') except SystemExit as e: if e.code != 0: raise DistutilsSetupError("There were test failures!") - self.run_command('sdist') - if self.pypi: cmd_obj = self.distribution.get_command_obj('upload') cmd_obj.sign = True @@ -130,8 +188,6 @@ def run(self): self._sign() self._tag() - self._publish() - self.announce("Release complete! Don't forget to:", log.INFO) self.announce("") self.announce(" git push && git push --tags", log.INFO) diff --git a/setup.py b/setup.py index 4ea6325..c12e6cc 100755 --- a/setup.py +++ b/setup.py @@ -25,24 +25,11 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from setuptools import setup -from release import release -import re - -VERSION_PATTERN = re.compile(r"(?m)^__version__\s*=\s*['\"](.+)['\"]$") - - -def get_version(): - """Return the current version as defined by u2fval_client/__init__.py.""" - - with open('u2fval_client/__init__.py', 'r') as f: - match = VERSION_PATTERN.search(f.read()) - return match.group(1) +from release import setup setup( name='u2fval-client', - version=get_version(), author='Dain Nilsson', author_email='dain@yubico.com', description='Python based U2FVAL connector library', @@ -50,13 +37,11 @@ def get_version(): maintainer_email='ossmaint@yubico.com', url='https://github.com/Yubico/u2fval-client-python', license='BSD 2 clause', - packages=['u2fval_client'], install_requires=['requests'], test_suite='test', tests_require=[ 'httpretty', ], - cmdclass={'release': release}, classifiers=[ 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 2', diff --git a/u2fval_client/__init__.py b/u2fval_client/__init__.py index fbdd90d..ba9042b 100644 --- a/u2fval_client/__init__.py +++ b/u2fval_client/__init__.py @@ -25,4 +25,4 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -__version__ = '2.0.0-dev0' +__version__ = '2.0.0'