()
| 1 | import re |
| 2 | |
| 3 | def 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 | |
| 34 | main() |
no test coverage detected