forked from git-keeper/git-keeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump_version.py
More file actions
executable file
·89 lines (66 loc) · 2.39 KB
/
bump_version.py
File metadata and controls
executable file
·89 lines (66 loc) · 2.39 KB
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
#!/usr/bin/env python3
#
# Copyright 2018 Nathan Sommer and Ben Coleman
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
This script writes a new version number to the version.py files in all three
of the main packages.
Before running this script, place the new version number in the file named
VERSION.
The version string must have the form MAJOR.MINOR.PATCH as detailed in Semantic
Versioning 2.0: https://semver.org/
"""
import argparse
import os
from distutils.version import StrictVersion
import sys
package_paths = (
'git-keeper-client/gkeepclient',
'git-keeper-core/gkeepcore',
'git-keeper-server/gkeepserver',
)
def main():
if not os.path.isfile('VERSION'):
sys.exit('VERSION does not exist')
version = None
try:
with open('VERSION') as f:
version = f.read().strip()
except OSError as e:
error = 'Error reading VERSION: {}'.format(e)
sys.exit(error)
try:
strict_version = StrictVersion(version)
except ValueError:
sys.exit('{} is not a valid version string'.format(version))
print('Updating version to', version)
file_text = \
'''# This file was generated automatically and should not be edited manually.
# Instead, edit the VERSION file in the top level directory of the git-keeper
# project and then run bump_version.py.
__version__ = '{}'
'''.format(version)
for package_path in package_paths:
version_file_path = os.path.join(package_path, 'version.py')
try:
with open(version_file_path, 'w') as f:
f.write(file_text)
print('Wrote', version_file_path)
except OSError as e:
error = 'Error opening {}: {}'.format(version_file_path, e)
sys.exit(error)
print('Version updated successfully')
if __name__ == '__main__':
main()