|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Version bump script for vallm package. |
| 4 | +Updates version in pyproject.toml based on the specified bump type. |
| 5 | +""" |
| 6 | + |
| 7 | +import sys |
| 8 | +import re |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | + |
| 12 | +def bump_version(version_str, bump_type): |
| 13 | + """Bump version string based on type.""" |
| 14 | + # Parse version string (expected format: X.Y.Z) |
| 15 | + match = re.match(r'^(\d+)\.(\d+)\.(\d+)$', version_str) |
| 16 | + if not match: |
| 17 | + raise ValueError(f"Invalid version format: {version_str}") |
| 18 | + |
| 19 | + major, minor, patch = map(int, match.groups()) |
| 20 | + |
| 21 | + if bump_type == "patch": |
| 22 | + patch += 1 |
| 23 | + elif bump_type == "minor": |
| 24 | + minor += 1 |
| 25 | + patch = 0 |
| 26 | + elif bump_type == "major": |
| 27 | + major += 1 |
| 28 | + minor = 0 |
| 29 | + patch = 0 |
| 30 | + else: |
| 31 | + raise ValueError(f"Invalid bump type: {bump_type}") |
| 32 | + |
| 33 | + return f"{major}.{minor}.{patch}" |
| 34 | + |
| 35 | + |
| 36 | +def main(): |
| 37 | + if len(sys.argv) != 2: |
| 38 | + print("Usage: python bump_version.py <patch|minor|major>") |
| 39 | + sys.exit(1) |
| 40 | + |
| 41 | + bump_type = sys.argv[1] |
| 42 | + if bump_type not in ["patch", "minor", "major"]: |
| 43 | + print("Error: bump_type must be one of: patch, minor, major") |
| 44 | + sys.exit(1) |
| 45 | + |
| 46 | + # Read pyproject.toml |
| 47 | + pyproject_path = Path(__file__).parent.parent / "pyproject.toml" |
| 48 | + if not pyproject_path.exists(): |
| 49 | + print(f"Error: {pyproject_path} not found") |
| 50 | + sys.exit(1) |
| 51 | + |
| 52 | + content = pyproject_path.read_text() |
| 53 | + |
| 54 | + # Find current version |
| 55 | + version_match = re.search(r'^version\s*=\s*"([^"]+)"', content, re.MULTILINE) |
| 56 | + if not version_match: |
| 57 | + print("Error: version not found in pyproject.toml") |
| 58 | + sys.exit(1) |
| 59 | + |
| 60 | + current_version = version_match.group(1) |
| 61 | + new_version = bump_version(current_version, bump_type) |
| 62 | + |
| 63 | + # Update version in content |
| 64 | + new_content = re.sub( |
| 65 | + r'^version\s*=\s*"([^"]+)"', |
| 66 | + f'version = "{new_version}"', |
| 67 | + content, |
| 68 | + flags=re.MULTILINE |
| 69 | + ) |
| 70 | + |
| 71 | + # Write back to file |
| 72 | + pyproject_path.write_text(new_content) |
| 73 | + |
| 74 | + print(f"Bumped {bump_type} version: {current_version} → {new_version}") |
| 75 | + |
| 76 | + |
| 77 | +if __name__ == "__main__": |
| 78 | + main() |
0 commit comments