-
Notifications
You must be signed in to change notification settings - Fork 79
/
update_version.py
83 lines (66 loc) · 2.49 KB
/
update_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
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
#!usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os
import fileinput
def in_place_string_replace(filename: str, old_string: str, new_string: str) -> None:
"""
Replace a string in a file in place.
Args:
filename (str): The file to replace the string in
old_string (str): The string to replace
new_string (str): The string to replace with
"""
if os.path.exists(filename):
with fileinput.FileInput(filename, inplace=True) as file:
for line in file:
print(line.replace(old_string, new_string), end="")
def _update_version(old_version: str, new_version: str):
cwd = os.getcwd()
in_place_string_replace(
os.path.join(cwd, "GANDLF/version.py"), old_version, new_version
)
# find all yaml files in samples and testing directories
folders_to_iterate = [os.path.join(cwd, "samples"), os.path.join(cwd, "testing")]
files_where_version_is_stored = [
os.path.join(cwd, "mlcube/model_mlcube/workspace/config.yml"),
os.path.join(cwd, "tutorials/classification_medmnist_notebook/config.yaml"),
]
for folder in folders_to_iterate:
if os.path.isdir(folder):
files_in_dir = os.listdir(folder)
for file in files_in_dir:
if file.endswith(".yaml") or file.endswith(".yml"):
files_where_version_is_stored.append(os.path.join(folder, file))
old_version = old_version.replace("-dev", "")
new_version = new_version.replace("-dev", "")
# update the version.py file
for filename in files_where_version_is_stored:
in_place_string_replace(filename, old_version, new_version)
print("Version updated successfully in `version.py` and all configuration files!")
def main():
parser = argparse.ArgumentParser(
prog="Update GaNDLF version",
formatter_class=argparse.RawTextHelpFormatter,
description="Update versions when creating a new release of GaNDLF, also useful when updating the version for development.\n\n",
)
parser.add_argument(
"-ov",
"--old-version",
metavar="",
type=str,
required=True,
help="The old version number",
)
parser.add_argument(
"-nv",
"--new-version",
metavar="",
type=str,
required=True,
help="The new version number",
)
args = parser.parse_args()
_update_version(args.old_version, args.new_version)
if __name__ == "__main__":
main()