forked from wgergely/bookmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_version.py
39 lines (31 loc) · 1.47 KB
/
set_version.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
"""Set the version string."""
import os
import re
from PySide2 import QtWidgets, QtCore
pkg_root = QtCore.QFileInfo(f'{__file__}{os.path.sep}..').absoluteFilePath()
STRINGS = {
f'{pkg_root}/docs/src/conf.py': re.compile(r"release = \'(\d\.\d\.\d)\'", flags=re.MULTILINE),
f'{pkg_root}/bookmarks/__init__.py': re.compile(r"Version-v(\d\.\d\.\d)", flags=re.MULTILINE),
f'{pkg_root}/bookmarks/__init__.py': re.compile(r"__version__ = \'(\d\.\d\.\d)\'", flags=re.MULTILINE),
f'{pkg_root}/README.md': re.compile(r"Version-v(\d\.\d\.\d)", flags=re.MULTILINE),
f'{pkg_root}/bookmarks/maya/plugin.py': re.compile(r"__version__ = \'(\d\.\d\.\d)\'", flags=re.MULTILINE),
f'{pkg_root}/package/CMakeLists.txt': re.compile(r"VERSION (\d\.\d\.\d)", flags=re.MULTILINE),
f'{pkg_root}/docs/src/guide.rst': re.compile(r'.*(\d\.\d\.\d).*', flags=re.MULTILINE),
}
app = QtWidgets.QApplication()
version, res = QtWidgets.QInputDialog.getText(None, 'Enter Version', 'New Version')
if not res:
raise RuntimeError('Stopping...')
if not version:
raise RuntimeError('Must enter a valid version')
for k, v in STRINGS.items():
if not os.path.isfile(k):
raise RuntimeError(f'{k} does not exist.')
with open(k, 'r', encoding='utf-8') as f:
v = f.read()
s = STRINGS[k].search(v)
if not s:
raise RuntimeError(f'Could not parse {k}')
v = re.sub(s.group(1), version, v)
with open(k, 'w', encoding='utf-8') as f:
f.write(v)