Skip to content
Myr

make-release.py

This file

Path

scripts/make-release.py

146 lines · 3.8 KiB · Python

Last changed by

resolve merge conflictsKenneth Reitzbefore adoption31174fe

History of this file

Take it

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

Fixed a reference in the docs.Armin Ronacherbefore adoption8a46eec

lines 1–9why, 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.9

Merge pull request #1303 from Parkayun/masterMarkus Unterwaditzerbefore adoption5b98266

line 10why, one step back
10 :copyright: (c) 2015 by Armin Ronacher.

Fixed a reference in the docs.Armin Ronacherbefore adoption8a46eec

lines 11–12why, one step back
11 :license: BSD, see LICENSE for more details.
12"""

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 13why, one step back
13from __future__ import print_function

Fixed a reference in the docs.Armin Ronacherbefore adoption8a46eec

lines 14–84why, one step back
14import sys
15import os16import re17from datetime import datetime, date18from subprocess import Popen, PIPE1920_date_clean_re = re.compile(r'(\d+)(st|nd|rd|th)')212223def parse_changelog():24 with open('CHANGES') as f:25 lineiter = iter(f)26 for line in lineiter:27 match = re.search('^Version\s+(.*)', line.strip())28 if match is None:29 continue30 version = match.group(1).strip()31 if lineiter.next().count('-') != len(match.group(0)):32 continue33 while 1:34 change_info = lineiter.next().strip()35 if change_info:36 break3738 match = re.search(r'released on (\w+\s+\d+\w+\s+\d+)'39 r'(?:, codename (.*))?(?i)', change_info)40 if match is None:41 continue4243 datestr, codename = match.groups()44 return version, parse_date(datestr), codename454647def bump_version(version):48 try:49 parts = map(int, version.split('.'))50 except ValueError:51 fail('Current version is not numeric')52 parts[-1] += 153 return '.'.join(map(str, parts))545556def parse_date(string):57 string = _date_clean_re.sub(r'\1', string)58 return datetime.strptime(string, '%B %d %Y')596061def set_filename_version(filename, version_number, pattern):62 changed = []6364 def inject_version(match):65 before, old, after = match.groups()66 changed.append(True)67 return before + version_number + after68 with open(filename) as f:69 contents = re.sub(r"^(\s*%s\s*=\s*')(.+?)(')(?sm)" % pattern,70 inject_version, f.read())7172 if not changed:73 fail('Could not find %s in %s', pattern, filename)7475 with open(filename, 'w') as f:76 f.write(contents)777879def set_init_version(version):80 info('Setting __init__.py version to %s', version)81 set_filename_version('flask/__init__.py', version, '__version__')828384def build_and_upload():

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 85why, one step back
85 Popen([sys.executable, 'setup.py', 'release', 'sdist', 'bdist_wheel', 'upload']).wait()

Fixed a reference in the docs.Armin Ronacherbefore adoption8a46eec

lines 86–88why, one step back
86
8788def fail(message, *args):

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 89why, one step back
89 print('Error:', message % args, file=sys.stderr)

Fixed a reference in the docs.Armin Ronacherbefore adoption8a46eec

lines 90–93why, one step back
90 sys.exit(1)
919293def info(message, *args):

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 94why, one step back
94 print(message % args, file=sys.stderr)

Fixed a reference in the docs.Armin Ronacherbefore adoption8a46eec

lines 95–146why, one step back
95
9697def get_git_tags():98 return set(Popen(['git', 'tag'], stdout=PIPE).communicate()[0].splitlines())99100101def git_is_clean():102 return Popen(['git', 'diff', '--quiet']).wait() == 0103104105def make_git_commit(message, *args):106 message = message % args107 Popen(['git', 'commit', '-am', message]).wait()108109110def make_git_tag(tag):111 info('Tagging "%s"', tag)112 Popen(['git', 'tag', tag]).wait()113114115def main():116 os.chdir(os.path.join(os.path.dirname(__file__), '..'))117118 rv = parse_changelog()119 if rv is None:120 fail('Could not parse changelog')121122 version, release_date, codename = rv123 dev_version = bump_version(version) + '-dev'124125 info('Releasing %s (codename %s, release date %s)',126 version, codename, release_date.strftime('%d/%m/%Y'))127 tags = get_git_tags()128129 if version in tags:130 fail('Version "%s" is already tagged', version)131 if release_date.date() != date.today():132 fail('Release date is not today (%s != %s)',133 release_date.date(), date.today())134135 if not git_is_clean():136 fail('You have uncommitted changes in git')137138 set_init_version(version)139 make_git_commit('Bump version number to %s', version)140 make_git_tag(version)141 build_and_upload()142 set_init_version(dev_version)143144145if __name__ == '__main__':146 main()