MCPcopy Index your code
hub / github.com/omkarcloud/botasaurus / main

Function main

increment_version.py:3–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import re
2
3def main():
4 with open("setup.py", "r") as file:
5 setup_file = file.read()
6
7 # Match the version string using a robust pattern
8 version_match = re.search(r"version=['\"](.*?)['\"]", setup_file)
9
10 if version_match:
11 current_version = version_match.group(1).split(".")
12
13 # Increment the last part of the version (patch level)
14 try:
15 new_version = (
16 f"{current_version[0]}.{current_version[1]}.{int(current_version[2]) + 1}"
17 )
18 except ValueError:
19 print(
20 "Invalid version format in setup.py. Please use a valid semantic versioning format (e.g., 1.2.3)."
21 )
22 return
23
24 setup_file = re.sub(
25 r"version=['\"](.*?)['\"]", f"version='{new_version}'", setup_file
26 )
27
28 with open("setup.py", "w") as file:
29 file.write(setup_file)
30 print(f"Version incremented to: {new_version}")
31 else:
32 print("Version string not found in setup.py")
33
34main()

Callers 1

Calls 2

searchMethod · 0.80
writeMethod · 0.80

Tested by

no test coverage detected