#!/usr/bin/env python3 """ Version bumping script for ai-shell """ import re import sys from pathlib import Path def bump_version(version_type: str = "patch") -> None: """Bump version in __init__.py and pyproject.toml""" # Read current version from __init__.py init_file = Path("ai_shell/__init__.py") init_content = init_file.read_text() # Extract current version version_match = re.search(r'__version__ = "([^"]+)"', init_content) if not version_match: print("Error: Could not find version in __init__.py") sys.exit(1) current_version = version_match.group(1) major, minor, patch = map(int, current_version.split('.')) # Bump version if version_type == "major": major += 1 minor = 0 patch = 0 elif version_type == "minor": minor += 1 patch = 0 elif version_type == "patch": patch += 1 else: print(f"Error: Invalid version type '{version_type}'. Use 'major', 'minor', or 'patch'") sys.exit(1) new_version = f"{major}.{minor}.{patch}" # Update __init__.py new_init_content = re.sub( r'__version__ = "[^"]+"', f'__version__ = "{new_version}"', init_content ) init_file.write_text(new_init_content) # Update pyproject.toml pyproject_file = Path("pyproject.toml") pyproject_content = pyproject_file.read_text() new_pyproject_content = re.sub( r'version = "[^"]+"', f'version = "{new_version}"', pyproject_content ) pyproject_file.write_text(new_pyproject_content) print(f"Version bumped from {current_version} to {new_version}") if __name__ == "__main__": version_type = sys.argv[1] if len(sys.argv) > 1 else "patch" bump_version(version_type)