-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
finalize.py
62 lines (45 loc) · 1.4 KB
/
finalize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Finalize the repo for a release. Invokes towncrier and bumpversion.
"""
__requires__ = ['bump2version', 'towncrier', 'jaraco.develop>=7.21']
import pathlib
import re
import subprocess
import sys
from jaraco.develop import towncrier
bump_version_command = [
sys.executable,
'-m',
'bumpversion',
towncrier.release_kind(),
]
def get_version():
cmd = bump_version_command + ['--dry-run', '--verbose']
out = subprocess.check_output(cmd, text=True, encoding='utf-8')
return re.search('^new_version=(.*)', out, re.MULTILINE).group(1)
def update_changelog():
towncrier.run('build', '--yes')
_repair_changelog()
def _repair_changelog():
"""
Workaround for #2666
"""
changelog_fn = pathlib.Path('NEWS.rst')
changelog = changelog_fn.read_text(encoding='utf-8')
fixed = re.sub(r'^(v[0-9.]+)v[0-9.]+$', r'\1', changelog, flags=re.M)
changelog_fn.write_text(fixed, encoding='utf-8')
subprocess.check_output(['git', 'add', changelog_fn])
def bump_version():
cmd = bump_version_command + ['--allow-dirty']
subprocess.check_call(cmd)
def ensure_config():
"""
Double-check that Git has an e-mail configured.
"""
subprocess.check_output(['git', 'config', 'user.email'])
if __name__ == '__main__':
print("Cutting release at", get_version())
ensure_config()
towncrier.check_changes()
update_changelog()
bump_version()