Skip to content
Myr

make-release.py

This file

Path

scripts/make-release.py

164 lines · 4.3 KiB · Python

Last changed by

Improve release script to support new format and wheels.Armin Ronacherbefore adoption6bf78bc

History of this file

Take it

The walk stopped after 200 commits: lines older than b89d1a8 point at it.

Since we no longer support 2.5 we can use the builtin next() functionArmin Ronacherbefore adoptionb89d1a8

lines 1–18why, one step back
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-3"""4 make-release5 ~~~~~~~~~~~~67 Helper script that performs a release. Does pretty much everything8 automatically for us.910 :copyright: (c) 2011 by Armin Ronacher.11 :license: BSD, see LICENSE for more details.12"""13import sys14import os15import re16from datetime import datetime, date17from subprocess import Popen, PIPE18

Merge pull request #336 from berkerpeksag/wheel-supportArmin Ronacherbefore adoption76c3995

lines 19–22why, one step back
19try:
20 import wheel21except ImportError:22 wheel = None

Since we no longer support 2.5 we can use the builtin next() functionArmin Ronacherbefore adoptionb89d1a8

line 23why, one step back
23

Merge branch '2.7-maintenance'Armin Ronacherbefore adoption8db4791

lines 24–26why, one step back
24_date_strip_re = re.compile(r'(?<=\d)(st|nd|rd|th)')
2526

Since we no longer support 2.5 we can use the builtin next() functionArmin Ronacherbefore adoptionb89d1a8

lines 27–62why, one step back
27def parse_changelog():
28 with open('CHANGES') as f:29 lineiter = iter(f)30 for line in lineiter:31 match = re.search('^Version\s+(.*)', line.strip())32 if match is None:33 continue34 length = len(match.group(1))35 version = match.group(1).strip()36 if lineiter.next().count('-') != len(match.group(0)):37 continue38 while 1:39 change_info = lineiter.next().strip()40 if change_info:41 break4243 match = re.search(r'(?:codename (.*),\s*)?'44 r'released on (\w+\s+\d+\w+\s+\d+)(?i)',45 change_info)46 if match is None:47 continue4849 codename, datestr = match.groups()50 return version, parse_date(datestr), codename515253def bump_version(version):54 try:55 parts = map(int, version.split('.'))56 except ValueError:57 fail('Current version is not numeric')58 parts[-1] += 159 return '.'.join(map(str, parts))606162def parse_date(string):

Merge branch '2.7-maintenance'Armin Ronacherbefore adoption8db4791

line 63why, one step back
63 string = _date_strip_re.sub('', string)

Since we no longer support 2.5 we can use the builtin next() functionArmin Ronacherbefore adoptionb89d1a8

lines 64–94why, one step back
64 return datetime.strptime(string, '%B %d %Y')
656667def set_filename_version(filename, version_number, pattern):68 changed = []69 def inject_version(match):70 before, old, after = match.groups()71 changed.append(True)72 return before + version_number + after73 with open(filename) as f:74 contents = re.sub(r"^(\s*%s\s*=\s*')(.+?)(')(?sm)" % pattern,75 inject_version, f.read())7677 if not changed:78 fail('Could not find %s in %s', pattern, filename)7980 with open(filename, 'w') as f:81 f.write(contents)828384def set_init_version(version):85 info('Setting __init__.py version to %s', version)86 set_filename_version('jinja2/__init__.py', version, '__version__')878889def set_setup_version(version):90 info('Setting setup.py version to %s', version)91 set_filename_version('setup.py', version, 'version')929394def build_and_upload():

Improve release script to support new format and wheels.Armin Ronacherbefore adoption6bf78bc

line 95why, one step back
95 cmd = [sys.executable, 'setup.py', 'release', 'sdist', 'bdist_wheel', 'upload']

Merge pull request #336 from berkerpeksag/wheel-supportArmin Ronacherbefore adoption76c3995

lines 96–98why, one step back
96 if wheel is not None:
97 cmd.insert(4, 'bdist_wheel')98 Popen(cmd).wait()

Since we no longer support 2.5 we can use the builtin next() functionArmin Ronacherbefore adoptionb89d1a8

lines 99–135why, one step back
99
100101def fail(message, *args):102 print >> sys.stderr, 'Error:', message % args103 sys.exit(1)104105106def info(message, *args):107 print >> sys.stderr, message % args108109110def get_git_tags():111 return set(Popen(['git', 'tag'], stdout=PIPE).communicate()[0].splitlines())112113114def git_is_clean():115 return Popen(['git', 'diff', '--quiet']).wait() == 0116117118def make_git_commit(message, *args):119 message = message % args120 Popen(['git', 'commit', '-am', message]).wait()121122123def make_git_tag(tag):124 info('Tagging "%s"', tag)125 Popen(['git', 'tag', tag]).wait()126127128def main():129 os.chdir(os.path.join(os.path.dirname(__file__), '..'))130131 rv = parse_changelog()132 if rv is None:133 fail('Could not parse changelog')134135 version, release_date, codename = rv

Improve release script to support new format and wheels.Armin Ronacherbefore adoption6bf78bc

line 136why, one step back
136 dev_version = bump_version(version) + '.dev'

Since we no longer support 2.5 we can use the builtin next() functionArmin Ronacherbefore adoptionb89d1a8

lines 137–148why, one step back
137
138 info('Releasing %s (codename %s, release date %s)',139 version, codename, release_date.strftime('%d/%m/%Y'))140 tags = get_git_tags()141142 if version in tags:143 fail('Version "%s" is already tagged', version)144 if release_date.date() != date.today():145 fail('Release date is not today (%s != %s)', release_date.date(), date.today())146147 if not git_is_clean():148 fail('You have uncommitted changes in git')

Merge pull request #336 from berkerpeksag/wheel-supportArmin Ronacherbefore adoption76c3995

lines 149–152why, one step back
149
150 if wheel is None:151 print ('Warning: You need to install the wheel package '152 'to upload a wheel distribution.')

Since we no longer support 2.5 we can use the builtin next() functionArmin Ronacherbefore adoptionb89d1a8

lines 153–164why, one step back
153
154 set_init_version(version)155 set_setup_version(version)156 make_git_commit('Bump version number to %s', version)157 make_git_tag(version)158 build_and_upload()159 set_init_version(dev_version)160 set_setup_version(dev_version)161162163if __name__ == '__main__':164 main()