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 fileTake 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 back1#!/usr/bin/env python2# -*- 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 back13from __future__ import print_function14Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 15–16why, one step back15import os16import reclean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 17–19why, one step back17import sys18from datetime import date, datetime19from subprocess import PIPE, PopenMake slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 20–24why, one step back2021_date_strip_re = re.compile(r'(?<=\d)(st|nd|rd|th)')222324def parse_changelog():clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
line 25why, one step back25 with open('CHANGES.rst') as f:Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 26–28why, one step back26 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 back29Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 30–31why, one step back30 if match is None:31 continueclean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
line 32why, one step back32Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
line 33why, one step back33 version = match.group(1).strip()clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 34–35why, one step back3435 if next(lineiter).count('-') != len(match.group(0)):Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
line 36why, one step back36 continueclean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
line 37why, one step back37Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
line 38why, one step back38 while 1:clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 39–40why, one step back39 change_info = next(lineiter).strip()40Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 41–43why, one step back41 if change_info:42 break43clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 44–48why, one step back44 match = re.search(45 r'(?:codename (.*),\s*)?released on (\w+\s+\d+\w+\s+\d+)(?i)',46 change_info47 )48Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 49–57why, one step back49 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 back58 parts = [int(i) for i in version.split('.')]Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 59–60why, one step back59 except ValueError:60 fail('Current version is not numeric')clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
line 61why, one step back61Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 62–72why, one step back62 parts[-1] += 163 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 back73Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 74–77why, one step back74 def inject_version(match):75 before, old, after = match.groups()76 changed.append(True)77 return before + version_number + afterclean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
line 78why, one step back78Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
line 79why, one step back79 with open(filename) as f:clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 80–83why, one step back80 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 back8485 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 back103 cmd = [sys.executable, 'setup.py', 'sdist', 'bdist_wheel']Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 104–107why, one step back104 Popen(cmd).wait()105106107def fail(message, *args):clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
line 108why, one step back108 print('Error:', message % args, file=sys.stderr)Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 109–112why, one step back109 sys.exit(1)110111112def info(message, *args):clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
line 113why, one step back113 print(message % args, file=sys.stderr)Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 114–116why, one step back114115116def get_git_tags():clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 117–119why, one step back117 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 back120121122def 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 back140Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
lines 141–146why, one step back141 if rv is None:142 fail('Could not parse changelog')143144 version, release_date, codename = rv145 dev_version = bump_version(version) + '.dev'146clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 147–150why, one step back147 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 back151 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 back155Make slice work with async generatorsArmin Ronacherbefore adoptiona6e48b4
line 156why, one step back156 if release_date.date() != date.today():clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 157–160why, one step back157 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 back161162 if not git_is_clean():163 fail('You have uncommitted changes in git')164clean up MANIFEST.inDavid Lordbefore adoptiond9d3fc3
lines 165–168why, one step back165 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 back169170 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()