Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Commit

Permalink
Prepare release.
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Apr 7, 2017
1 parent feb23b5 commit 8c6ec1b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 66 deletions.
5 changes: 3 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
150 changes: 103 additions & 47 deletions release.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

# 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"),
]
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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)
Expand Down
17 changes: 1 addition & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,23 @@
# 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='[email protected]',
description='Python based U2FVAL connector library',
maintainer='Yubico Open Source Maintainers',
maintainer_email='[email protected]',
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',
Expand Down
2 changes: 1 addition & 1 deletion u2fval_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 8c6ec1b

Please sign in to comment.