|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import os |
| 3 | +import re |
| 4 | +import sys |
| 5 | + |
| 6 | + |
| 7 | +def bump_version(version, bump_type): |
| 8 | + major, minor, patch = map(int, version.split(".")) |
| 9 | + |
| 10 | + if bump_type == "major": |
| 11 | + major += 1 |
| 12 | + minor = 0 |
| 13 | + patch = 0 |
| 14 | + elif bump_type == "minor": |
| 15 | + minor += 1 |
| 16 | + patch = 0 |
| 17 | + elif bump_type == "patch": |
| 18 | + patch += 1 |
| 19 | + |
| 20 | + return f"{major}.{minor}.{patch}" |
| 21 | + |
| 22 | + |
| 23 | +def update_version_in_file(file_path, old_version, new_version): |
| 24 | + with open(file_path, "r") as file: |
| 25 | + content = file.read() |
| 26 | + |
| 27 | + content = content.replace( |
| 28 | + f'version = "{old_version}"', f'version = "{new_version}"' |
| 29 | + ) |
| 30 | + |
| 31 | + with open(file_path, "w") as file: |
| 32 | + file.write(content) |
| 33 | + |
| 34 | + |
| 35 | +def main(): |
| 36 | + bump_type = sys.argv[1] |
| 37 | + |
| 38 | + for package_dir in os.listdir("."): |
| 39 | + if os.path.isdir(package_dir) and package_dir.startswith("plain"): |
| 40 | + pyproject_path = os.path.join(package_dir, "pyproject.toml") |
| 41 | + |
| 42 | + with open(pyproject_path, "r") as file: |
| 43 | + content = file.read() |
| 44 | + |
| 45 | + version_match = re.search(r'version = "(.*?)"', content) |
| 46 | + if version_match: |
| 47 | + old_version = version_match.group(1) |
| 48 | + new_version = bump_version(old_version, bump_type) |
| 49 | + update_version_in_file(pyproject_path, old_version, new_version) |
| 50 | + print(f"Bumped {package_dir} from {old_version} to {new_version}") |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + main() |
0 commit comments