Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

gandlf_updateVersion 2.5 KB

You have to be logged in to leave a comment. Sign In
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
  1. #!usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import argparse, os, fileinput
  4. if __name__ == "__main__":
  5. parser = argparse.ArgumentParser(
  6. prog="GANDLF_UpdateVersion",
  7. formatter_class=argparse.RawTextHelpFormatter,
  8. description="Update versions when creating a new release of GaNDLF, also useful when updating the version for development.\n\n",
  9. )
  10. parser.add_argument(
  11. "-ov",
  12. "--old_version",
  13. metavar="",
  14. type=str,
  15. required=True,
  16. help="The old version number",
  17. )
  18. parser.add_argument(
  19. "-nv",
  20. "--new_version",
  21. metavar="",
  22. type=str,
  23. required=True,
  24. help="The new version number",
  25. )
  26. args = parser.parse_args()
  27. def in_place_string_replace(
  28. filename: str, old_string: str, new_string: str
  29. ) -> None:
  30. """
  31. Replace a string in a file in place.
  32. Args:
  33. filename (str): The file to replace the string in
  34. old_string (str): The string to replace
  35. new_string (str): The string to replace with
  36. """
  37. if os.path.exists(filename):
  38. with fileinput.FileInput(filename, inplace=True) as file:
  39. for line in file:
  40. print(line.replace(old_string, new_string), end="")
  41. cwd = os.getcwd()
  42. in_place_string_replace(
  43. os.path.join(cwd, "GANDLF/version.py"),
  44. args.old_version,
  45. args.new_version,
  46. )
  47. # find all yaml files in samples and testing directories
  48. folders_to_iterate = [
  49. os.path.join(cwd, "samples"),
  50. os.path.join(cwd, "testing"),
  51. ]
  52. files_where_version_is_stored = [
  53. os.path.join(cwd, "mlcube/model_mlcube/workspace/config.yml"),
  54. os.path.join(cwd, "tutorials/classification_medmnist_notebook/config.yaml"),
  55. ]
  56. for folder in folders_to_iterate:
  57. if os.path.isdir(folder):
  58. files_in_dir = os.listdir(folder)
  59. for file in files_in_dir:
  60. if file.endswith(".yaml") or file.endswith(".yml"):
  61. files_where_version_is_stored.append(os.path.join(folder, file))
  62. args.old_version = args.old_version.replace("-dev", "")
  63. args.new_version = args.new_version.replace("-dev", "")
  64. # update the version.py file
  65. for filename in files_where_version_is_stored:
  66. in_place_string_replace(filename, args.old_version, args.new_version)
  67. print("Version updated successfully in `version.py` and all configuration files!")
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...