-
Notifications
You must be signed in to change notification settings - Fork 4
/
bump.py
executable file
·163 lines (139 loc) · 4.41 KB
/
bump.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python3
from datetime import datetime
import sys
import subprocess # for check_output
from etm.__version__ import version
def check_output(cmd):
if not cmd:
return
res = ''
try:
res = subprocess.check_output(
cmd,
stderr=subprocess.STDOUT,
shell=True,
universal_newlines=True,
encoding='UTF-8',
)
return True, res
except subprocess.CalledProcessError as e:
lines = e.output.strip().split('\n')
msg = lines[-1]
return False, msg
import etm.options as options
# check_output = view.check_output
ok, gb = check_output('git branch')
print('branch:')
print(gb)
ok, gs = check_output('git status -s')
if gs:
print('status:')
print(gs)
print('There are uncommitted changes.')
ans = input('Continue anyway? [yN] ')
if not (ans and ans.lower() == 'y'):
sys.exit()
# PEP 440 extensions
# possible_extensions = ['a', 'b', 'rc', '.post', '.dev']
# For etm only the following will be used
possible_extensions = ['a', 'b', 'rc']
pre = post = version
ext = 'a'
ext_num = 1
for poss in possible_extensions:
if poss in version:
ext = poss
pre, post = version.split(ext)
ext_num = int(post) + 1
break
extension_options = {
'a': {'a': f'a{ext_num}', 'b': 'b0', 'r': 'rc0'},
'b': {'b': f'b{ext_num}', 'r': 'rc0'},
'rc': {'r': f'rc{ext_num}'},
}
# print(version, pre, post, ext)
new_ext = f'{pre}{ext}{ext_num}'
# print(pre)
major, minor, patch = pre.split('.')
# print(major, minor, patch)
b_patch = '.'.join([major, minor, str(int(patch) + 1)])
b_minor = '.'.join([major, str(int(minor) + 1), '0'])
b_major = '.'.join([str(int(major) + 1), '0', '0'])
# print(b_patch, b_minor, b_major)
# parts = pre.split('.')
# parts[-1] = str(int(parts[-1]) + 1)
# new_patch = ".".join(parts)
opts = [f'The current version is {version}']
if ext and ext in extension_options:
i = 0
for k, v in extension_options[ext].items():
opts.append(f' {k}: {pre}{v}')
opts.append(f' p: {b_patch}')
opts.append(f' n: {b_minor}')
opts.append(f' j: {b_major}')
import os
version_file = os.path.join(os.getcwd(), 'etm', '__version__.py')
print('\n'.join(opts))
res = input(f'Which new version? ')
new_version = ''
res = res.lower()
if not res:
print('cancelled')
sys.exit()
bmsg = ''
if res in extension_options[ext]:
new_version = f'{pre}{extension_options[ext][res]}'
bmsg = 'release candidate version update'
elif res == 'p':
new_version = b_patch
bmsg = 'patch version update'
elif res == 'n':
new_version = b_minor
bmsg = 'minor version update'
elif res == 'j':
new_version = b_major
bmsg = 'major version update'
tplus = ''
if bmsg:
tplus = input(f'Optional {bmsg} message:\n')
tmsg = f'Tagged version {new_version}. {tplus}'
print(f'\nThe tag message for the new version will be:\n{tmsg}\n')
ans = input(f'Commit and tag new version: {new_version}? [yN] ')
if ans.lower() != 'y':
print('cancelled')
sys.exit()
if new_version:
with open(version_file, 'w') as fo:
fo.write(f"version = '{new_version}'")
print(f'new version: {new_version}')
tmsg = f'Tagged version {new_version}. {tplus}'
check_output(f"git commit -a -m '{tmsg}'")
ok, version_info = check_output("git log --pretty=format:'%ai' -n 1")
check_output(f"git tag -a -f '{new_version}' -m '{version_info}'")
count = 60
# check_output(
# f"echo 'Recent tagged changes as of {datetime.now()}:' > CHANGES.txt"
# )
check_output(
# f"git log --pretty=format:'- %ar%d %an%n %h %ai%n%w(70,4,4)%B' --max-count={count} --no-walk --tags >> CHANGES.txt"
f"git log --pretty=format:'%as %h %an%n%w(70,4,4)%B' --max-count={count} > CHANGES.txt"
)
check_output(f"git commit -a --amend -m '{tmsg}'")
ans = input('switch to master and merge working? [yN] ')
if ans.lower() != 'y':
print('cancelled')
sys.exit()
ok, res = check_output(
f'git push origin && git checkout master && git merge working && git push origin && git checkout working'
)
if res:
print(res)
ans = input('upload sdist to PyPi using twine? [yN] ')
if ans.lower() != 'y':
print('cancelled')
sys.exit()
ok, res = check_output('./upload_sdist.sh')
if res:
print(res)
else:
print(f'retained version: {version}')