forked from modflowpy/flopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateversion.py
73 lines (61 loc) · 2.45 KB
/
updateversion.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
from __future__ import print_function
import subprocess
import os
import sys
import datetime
def update_version(utag=False, major=False, minor=False):
from flopy import __version__
vmajor = __version__.strip().split('.')[-3]
vminor = __version__.strip().split('.')[-2]
vfeature = __version__.strip().split('.')[-1]
if major:
vmajor = int(vmajor) + 1
vminor = 0
vfeature = 0
elif minor:
vmajor = int(vmajor)
vminor = int(vminor) + 1
vfeature = 0
else:
vmajor = int(vmajor)
vminor = int(vminor)
vfeature = int(vfeature) + 1
version_type = ('{}'.format(vmajor), '{}'.format(vminor), '{}'.format(vfeature))
version = '.'.join(version_type)
b = subprocess.Popen(("git", "describe", "--match", "build"), stdout=subprocess.PIPE).communicate()[0]
build = int(b.decode().strip().split('-')[1]) + 1
print('Updating version:')
print(' ', __version__, '->', version)
# write new version file
f = open(os.path.normpath('flopy/version.py'), 'w')
f.write('#flopy version file automatically created using...{0}\n'.format(os.path.basename(__file__)))
f.write('# created on......{0}\n'.format(datetime.datetime.now().strftime("%B %d, %Y %H:%M:%S")))
f.write("__version__='{0}'\n".format(version))
f.write("__build__='{0}.{1}'\n".format(version, build))
f.close()
# commit version number change to github
cmdtag = 'git commit ./flopy/version.py -m "version number update"'
os.system(cmdtag)
cmdtag = 'git push'
os.system(cmdtag)
# update version tag
if utag:
cmdtag = 'git tag -a {0} -m "Version {0}"'.format(version)
os.system(cmdtag)
cmdtag = 'git push --tags'
os.system(cmdtag)
if __name__ == "__main__":
utag = False
major = False
minor = False
for arg in sys.argv:
if arg.lower() == '--tag' or arg.lower() == '-t':
utag = True
sys.stdout.write(' Will update git tag with version number.\n')
elif arg.lower() == '--major' or arg.lower() == '-ma':
major = True
sys.stdout.write(' Will update major version number by one.\n')
elif arg.lower() == '--minor' or arg.lower() == '-mi':
minor = True
sys.stdout.write(' Will update minor version number by one.\n')
update_version(utag, major, minor)