-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathset_vtk_version.py
More file actions
43 lines (33 loc) · 1.53 KB
/
set_vtk_version.py
File metadata and controls
43 lines (33 loc) · 1.53 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
from common import SLICER_DIR
from pathlib import Path
import re
import sys
# This is a simple regex that matches most valid python package version
VERSION_PATTERN = r'([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?'
# List of package name to replace version in given file
FILES = {
"vtk": Path(SLICER_DIR) / "SlicerCore" / "pyproject.toml",
"vtk-sdk": Path(SLICER_DIR) / "SlicerCore" / "pyproject.toml",
"vtk-sdk": Path(SLICER_DIR) / "SlicerCore" / "tests" / "packages" / "build_module" / "pyproject.toml",
"vtk-sdk": Path(SLICER_DIR) / "SlicerCore" / "tests" / "packages" / "find_package" / "pyproject.toml",
"vtk-sdk": Path(SLICER_DIR) / "SlicerCoreSDK" / "pyproject.toml",
}
def patch_version(pyproject: Path, name: str, version: str):
"""Replace occurence of {name}==X.Y.Z with {name}=={version} in file {pyproject}"""
new_content = ""
with open(pyproject, "r") as file:
new_content = re.sub(f"{name}=={VERSION_PATTERN}", f"{name}=={version}", file.read())
with open(pyproject, "w") as file:
file.write(new_content)
def main():
if len(sys.argv) < 2:
print(f"Usage: python set_vtk_version.py <vtk-version>")
exit(1)
version = sys.argv[1]
if not re.match(VERSION_PATTERN, version):
print(f"Given version, {version}, is not a valid version identifier")
exit(1)
for package, file in FILES.items():
patch_version(file, package, version)
if __name__ == '__main__':
main()