Permalink
Browse files

Release automation

  • Loading branch information...
1 parent 3f09f82 commit eb1ac949f9f7cb09561a22231e0017326479fd9f @vmalloc vmalloc committed Jul 30, 2013
Showing with 162 additions and 1 deletion.
  1. +1 −1 CHANGES
  2. +3 −0 Makefile
  3. +1 −0 logbook/__init__.py
  4. +151 −0 scripts/make-release.py
  5. +6 −0 setup.cfg
View
@@ -12,7 +12,7 @@ Version 0.5.0 (future)
Version 0.4.2
-------------
-Released on June 2th 2013.
+Released on June 2nd 2013.
- Fixed Python 3.x compatibility, including speedups
- Dropped Python 2.4 support. Python 2.4 support caused a lot of hacks in the code and introduced duplication to the test code. In addition, it is impossible to cover 2.4-3.x with a single tox installation, which may introduce unwitting code breakage. Travis also does not support Python 2.4 so the chances of accidentally breaking this support were very high as it was...
View
@@ -27,6 +27,9 @@ upload-docs: docs
docs:
make -C docs html SPHINXOPTS=-Aonline=1
+release:
+ python scripts/make-release.py
+
logbook/_speedups.so: logbook/_speedups.pyx
cython logbook/_speedups.pyx
python setup.py build
View
@@ -23,6 +23,7 @@
LimitingHandlerMixin, WrapperHandler, FingersCrossedHandler, \
GroupHandler
+__version__ = '0.5.0-dev'
# create an anonymous default logger and provide all important
# methods of that logger as global functions
View
@@ -0,0 +1,151 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+ make-release
+ ~~~~~~~~~~~~
+
+ Helper script that performs a release. Does pretty much everything
+ automatically for us.
+
+ :copyright: (c) 2011 by Armin Ronacher.
+ :license: BSD, see LICENSE for more details.
+"""
+import sys
+import os
+import re
+from datetime import datetime, date
+from subprocess import Popen, PIPE
+
+_date_clean_re = re.compile(r'(\d+)(st|nd|rd|th)')
+
+
+def parse_changelog():
+ with open('CHANGES') as f:
+ lineiter = iter(f)
+ for line in lineiter:
+ match = re.search('^Version\s+(.*)', line.strip())
+ if match is None:
+ continue
+ length = len(match.group(1))
+ version = match.group(1).strip()
+ if lineiter.next().count('-') != len(match.group(0)):
+ continue
+ while 1:
+ change_info = lineiter.next().strip()
+ if change_info:
+ break
+
+ match = re.search(r'released on (\w+\s+\d+\w+\s+\d+)'
+ r'(?:, codename (.*))?(?i)', change_info)
+ if match is None:
+ continue
+
+ datestr, codename = match.groups()
+ return version, parse_date(datestr), codename
+
+
+def bump_version(version):
+ try:
+ parts = map(int, version.split('.'))
+ except ValueError:
+ fail('Current version is not numeric')
+ parts[-1] += 1
+ return '.'.join(map(str, parts))
+
+
+def parse_date(string):
+ string = _date_clean_re.sub(r'\1', string)
+ return datetime.strptime(string, '%B %d %Y')
+
+
+def set_filename_version(filename, version_number, pattern):
+ changed = []
+ def inject_version(match):
+ before, old, after = match.groups()
+ changed.append(True)
+ return before + version_number + after
+ with open(filename) as f:
+ contents = re.sub(r"^(\s*%s\s*=\s*')(.+?)(')(?sm)" % pattern,
+ inject_version, f.read())
+
+ if not changed:
+ fail('Could not find %s in %s', pattern, filename)
+
+ with open(filename, 'w') as f:
+ f.write(contents)
+
+
+def set_init_version(version):
+ info('Setting __init__.py version to %s', version)
+ set_filename_version('logbook/__init__.py', version, '__version__')
+
+
+def set_setup_version(version):
+ info('Setting setup.py version to %s', version)
+ set_filename_version('setup.py', version, 'version')
+
+
+def build_and_upload():
+ Popen([sys.executable, 'setup.py', 'release', 'sdist', 'upload']).wait()
+
+
+def fail(message, *args):
+ print >> sys.stderr, 'Error:', message % args
+ sys.exit(1)
+
+
+def info(message, *args):
+ print >> sys.stderr, message % args
+
+
+def get_git_tags():
+ return set(Popen(['git', 'tag'], stdout=PIPE).communicate()[0].splitlines())
+
+
+def git_is_clean():
+ return Popen(['git', 'diff', '--quiet']).wait() == 0
+
+
+def make_git_commit(message, *args):
+ message = message % args
+ Popen(['git', 'commit', '-am', message]).wait()
+
+
+def make_git_tag(tag):
+ info('Tagging "%s"', tag)
+ Popen(['git', 'tag', tag]).wait()
+
+
+def main():
+ os.chdir(os.path.join(os.path.dirname(__file__), '..'))
+
+ rv = parse_changelog()
+ if rv is None:
+ fail('Could not parse changelog')
+
+ version, release_date, codename = rv
+ dev_version = bump_version(version) + '-dev'
+
+ info('Releasing %s (codename %s, release date %s)',
+ version, codename, release_date.strftime('%d/%m/%Y'))
+ tags = get_git_tags()
+
+ if version in tags:
+ fail('Version "%s" is already tagged', version)
+ if release_date.date() != date.today():
+ fail('Release date is not today (%s != %s)' % (release_date.date(), date.today()))
+
+ if not git_is_clean():
+ fail('You have uncommitted changes in git')
+
+ set_init_version(version)
+ set_setup_version(version)
+ make_git_commit('Bump version number to %s', version)
+ make_git_tag(version)
+ build_and_upload()
+ set_init_version(dev_version)
+ set_setup_version(dev_version)
+
+
+if __name__ == '__main__':
+ main()
View
@@ -5,3 +5,9 @@ all_files = 1
[upload_docs]
upload-dir = docs/_build/html
+
+[egg_info]
+tag_date = true
+
+[aliases]
+release = egg_info -RDb ''

1 comment on commit eb1ac94

The documentation at http://pythonhosted.org/Logbook/ still mentions version 0.4

Please sign in to comment.