-
Notifications
You must be signed in to change notification settings - Fork 5
/
publish.py
executable file
·256 lines (195 loc) · 7.86 KB
/
publish.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import os
import re
import sys
from os.path import abspath, join, pardir, isfile
"""
required packages
numpy
these packages have to be installed in virtual environment in use:
for testing:
pip-tools
rstcheck
pytest
for uploading:
twine
--cov-config=tox.ini
pip-tools package:
TODO write bash script for this
its important to pin requirements to get reproducible errors!
compile a new requirements file (with the latest versions)
source activate tzEnv
pip-compile --upgrade
same as?!:
pip-compile --output-file requirements.txt requirements.in
pip-compile --output-file requirements_numba.txt requirements_numba.in
only update the flask package:
pip-compile --upgrade-package flask
compile a new requirements file (with versions currently used in the virtual env )
pip-compile --generate-hashes requirements_numba.in
do NOT sync. will install ONLY the packages specified! (no more tox etc. installed!)
pip-sync
commands
tox -r to rebuild your tox virtualenvs when you've made changes to requirements setup
rstcheck *.rst
tox -r -e py36-codestyle
tox -r -e py36
"""
PACKAGE = 'timezonefinderL'
def get_version(package=PACKAGE):
"""
Return package version as listed in `__version__` in `__init__.py`.
"""
init_py = open(join(package, '__init__.py')).read()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
def set_version(new_version_number=None, old_version_number=''):
"""
Set package version as listed in `__version__` in `__init__.py`.
"""
if new_version_number is None:
return ValueError
import fileinput
import sys
file = join(PACKAGE, '__init__.py')
for line in fileinput.input(file, inplace=1):
if old_version_number in line:
line = line.replace(old_version_number, new_version_number)
sys.stdout.write(line)
def convert_version(new_version_input='', old_version='1.0.0'):
new_version_input = re.search('\d\.\d\.\d+', new_version_input)
if new_version_input is None:
return None
else:
new_version_input = new_version_input.group()
# print(new_version_input)
split_new_version = [int(x) for x in new_version_input.split('.')]
# print(split_new_version)
split_old_version = [int(x) for x in old_version.split('.')]
# print(split_old_version)
for i in range(3):
if split_new_version[i] > split_old_version[i]:
break
if split_new_version[i] < split_old_version[i]:
return None
return new_version_input
def routine(cmd=None, message='', option1='next', option2='exit'):
while 1:
print(message)
if cmd:
print('running command:', cmd)
os.system(cmd)
print('__________\nDone. Options:')
print('1)', option1)
print('2)', option2)
print('anything else to repeat this step.')
try:
inp = int(input())
if inp == 1:
print('==============')
break
if inp == 2:
sys.exit()
except ValueError:
pass
print('================')
if __name__ == "__main__":
print('Do you want to switch to the "dev" branch? Commit before switching branch!')
print('1) yes, change now.')
print('2) no, exit')
print('anything else skip.')
try:
inp = int(input())
if inp == 1:
os.system('git checkout dev')
print('==============')
if inp == 2:
sys.exit()
except ValueError:
pass
# TODO run authors tests
old_version = get_version()
print('The actual version number is:', old_version)
print('Enter new version number:')
version_input = None
while 1:
try:
version_input = input()
except ValueError:
pass
version_number = convert_version(version_input, old_version)
if version_number is not None:
set_version(version_number, old_version, )
break
print('Invalid version input. Should be of format "x.x.xxx" and higher than the old version.')
version = get_version()
print('version number has been set to:', version)
print('=====================')
routine(None, 'Are all dependencies written in setup.py, requirements_numba.in/.txt and the Readme?',
'OK. Continue',
'Exit')
routine(None, 'Remember to write a changelog now for version %s' % version, 'Done. Continue', 'Exit')
routine(None,
'Maybe re-pin the test dependencies (requirements.txt) with pip-compile!'
' Commands are written in the beginning of this script',
'Done. Run tests', 'Exit')
# print('Enter virtual env name:')
# virtual env has to be given!
# virt_env_name = input()
virt_env_name = 'tzEnv'
virt_env_act_command = 'source activate ' + virt_env_name.strip() + '; '
print('___________')
print('Running TESTS:')
# routine(virt_env_act_command + "pip-compile requirements_numba.in;pip-sync",
# 'pinning the requirements.txt and bringing virtualEnv to exactly the specified state:', 'next: build check')
routine(virt_env_act_command + "rstcheck *.rst", 'checking syntax of all .rst files:', 'next: build check')
# IMPORTANT: -r flag to rebuild tox virtual env
# only when dependencies have changed!
rebuild_flag = ''
print('when the dependencies (in requirements.txt) have changed enter 1 (-> rebuild tox)')
try:
inp = int(input())
if inp == 1:
rebuild_flag = ' -r'
except ValueError:
pass
# routine(virt_env_act_command + "tox" + rebuild_flag, 'checking syntax, codestyle and imports', 'continue')
routine(virt_env_act_command + "tox" + rebuild_flag + " -e py36-codestyle",
'checking syntax, codestyle and imports', 'continue')
routine(virt_env_act_command + "tox" + rebuild_flag + " -e py36", 'build tests py3', 'continue')
print('Tests finished.')
routine(None,
'Please commit your changes, push and wait if Travis tests build successfully. '
'Only then merge them into the master.',
'Build successful. Publish and upload now.', 'Exit.')
# TODO do this automatically, problem are the commit messages (often the same as changelog)
# git commit --message
# git push dev
# if not in master
# TODO ask to push in master
# git merge ...
# TODO switching to master
# TODO wait for Travis to finish
print('=================')
print('PUBLISHING:')
# routine("python3 setup.py sdist bdist_wheel upload", 'Uploading the package now.') # deprecated
# new twine publishing routine:
# https://packaging.python.org/tutorials/packaging-projects/
routine("python3 setup.py sdist bdist_wheel", 'building the package now.')
path = abspath(join(__file__, pardir, 'dist'))
all_archives_this_version = [f for f in os.listdir(path) if isfile(join(path, f)) and version_number in f]
paths2archives = [abspath(join(path, f)) for f in all_archives_this_version]
command = "twine upload --repository-url https://test.pypi.org/legacy/ " + ' '.join(paths2archives)
# upload all archives of this version
routine(virt_env_act_command + command, 'testing if upload works.')
command = "twine upload " + ' '.join(paths2archives)
routine(virt_env_act_command + command, 'real upload to PyPI.')
# tag erstellen
routine(None, 'Do you want to create a git release tag?', 'Yes', 'No')
routine("git tag -a v%s -m 'Version %s'" % (version, version), 'Creating tag', 'Continue')
routine(None, 'Do you want to push the git release tag?', 'Yes', 'No')
# in den master pushen
os.system("git push --tags")
print('______________')
print('Publishing Done.')
print('now run:')
print('(only when the upload didnt work) python3 setup.py bdist_wheel upload')
print('sudo -H pip install ' + PACKAGE + ' --upgrade')