Skip to content
Myr

make-release.py

This file

Path

scripts/make-release.py

180 lines · 4.2 KiB · Python

Last changed by

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

History of this file

Take it

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

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 1–12why, 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"""

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 13–14why, one step back
13from __future__ import print_function
14

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 15–16why, one step back
15import os
16import re

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 17–19why, one step back
17import sys
18from datetime import date, datetime19from subprocess import PIPE, Popen

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 20–24why, one step back
20
21_date_strip_re = re.compile(r'(?<=\d)(st|nd|rd|th)')222324def parse_changelog():

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 25why, one step back
25 with open('CHANGES.rst') as f:

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 26–28why, one step back
26 lineiter = iter(f)
27 for line in lineiter:28 match = re.search('^Version\s+(.*)', line.strip())

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 29why, one step back
29

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 30–31why, one step back
30 if match is None:
31 continue

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 32why, one step back
32

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

line 33why, one step back
33 version = match.group(1).strip()

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 34–35why, one step back
34
35 if next(lineiter).count('-') != len(match.group(0)):

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

line 36why, one step back
36 continue

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 37why, one step back
37

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

line 38why, one step back
38 while 1:

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 39–40why, one step back
39 change_info = next(lineiter).strip()
40

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 41–43why, one step back
41 if change_info:
42 break43

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 44–48why, one step back
44 match = re.search(
45 r'(?:codename (.*),\s*)?released on (\w+\s+\d+\w+\s+\d+)(?i)',46 change_info47 )48

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 49–57why, one step back
49 if match is None:
50 continue5152 codename, datestr = match.groups()53 return version, parse_date(datestr), codename545556def bump_version(version):57 try:

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 58why, one step back
58 parts = [int(i) for i in version.split('.')]

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 59–60why, one step back
59 except ValueError:
60 fail('Current version is not numeric')

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 61why, one step back
61

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 62–72why, one step back
62 parts[-1] += 1
63 return '.'.join(map(str, parts))646566def parse_date(string):67 string = _date_strip_re.sub('', string)68 return datetime.strptime(string, '%B %d %Y')697071def set_filename_version(filename, version_number, pattern):72 changed = []

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 73why, one step back
73

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 74–77why, one step back
74 def inject_version(match):
75 before, old, after = match.groups()76 changed.append(True)77 return before + version_number + after

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 78why, one step back
78

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

line 79why, one step back
79 with open(filename) as f:

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 80–83why, one step back
80 contents = re.sub(
81 r"^(\s*%s\s*=\s*')(.+?)(')(?sm)" % pattern,82 inject_version, f.read()83 )

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 84–102why, one step back
84
85 if not changed:86 fail('Could not find %s in %s', pattern, filename)8788 with open(filename, 'w') as f:89 f.write(contents)909192def set_init_version(version):93 info('Setting __init__.py version to %s', version)94 set_filename_version('jinja2/__init__.py', version, '__version__')959697def set_setup_version(version):98 info('Setting setup.py version to %s', version)99 set_filename_version('setup.py', version, 'version')100101102def build_and_upload():

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

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

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 104–107why, one step back
104 Popen(cmd).wait()
105106107def fail(message, *args):

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

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

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 109–112why, one step back
109 sys.exit(1)
110111112def info(message, *args):

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

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

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 114–116why, one step back
114
115116def get_git_tags():

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 117–119why, one step back
117 return set(
118 Popen(['git', 'tag'], stdout=PIPE).communicate()[0].splitlines()119 )

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 120–139why, one step back
120
121122def git_is_clean():123 return Popen(['git', 'diff', '--quiet']).wait() == 0124125126def make_git_commit(message, *args):127 message = message % args128 Popen(['git', 'commit', '-am', message]).wait()129130131def make_git_tag(tag):132 info('Tagging "%s"', tag)133 Popen(['git', 'tag', tag]).wait()134135136def main():137 os.chdir(os.path.join(os.path.dirname(__file__), '..'))138139 rv = parse_changelog()

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 140why, one step back
140

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 141–146why, one step back
141 if rv is None:
142 fail('Could not parse changelog')143144 version, release_date, codename = rv145 dev_version = bump_version(version) + '.dev'146

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 147–150why, one step back
147 info(
148 'Releasing %s (codename %s, release date %s)',149 version, codename, release_date.strftime('%d/%m/%Y')150 )

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 151–154why, one step back
151 tags = get_git_tags()
152153 if version in tags:154 fail('Version "%s" is already tagged', version)

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

line 155why, one step back
155

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

line 156why, one step back
156 if release_date.date() != date.today():

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 157–160why, one step back
157 fail(
158 'Release date is not today (%s != %s)',159 release_date.date(), date.today()160 )

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 161–164why, one step back
161
162 if not git_is_clean():163 fail('You have uncommitted changes in git')164

clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3

lines 165–168why, one step back
165 try:
166 import wheel167 except ImportError:168 fail('You need to install the wheel package.')

Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4

lines 169–180why, one step back
169
170 set_init_version(version)171 set_setup_version(version)172 make_git_commit('Bump version number to %s', version)173 make_git_tag(version)174 build_and_upload()175 set_init_version(dev_version)176 set_setup_version(dev_version)177178179if __name__ == '__main__':180 main()